开发者

Fill object data from several tables using hibernate mapping

I'd like to know if it is possible to fill up a class data from database using the hibernate hbm (mapping).

For instance:

public class someClass {  
    List<OtherClass> otherClasses;  
    List<YetAnotherClass> yetAnotherClasses;  
    //Constructors ?  

    class OtherClass {  
        String name;  
        //setters, getters  
    }  

    class YetAnotherClass {  
        String name;  
        //setters, getters  
    }
    //setters, getters  
}

Using an hbm can I fill in the da开发者_Go百科ta from tables OTHER_CLASS_TABLE and YET_ANOTHER_CLASS_TABLE?

I have no such SOME_CLASS_TABLE since this info is for viewing only.

I've been playing with the <join table=""><subselect> and different constructors... But it is not working

Thanks!

Sorry for my english!


So you have a class which seems not to be a real entity, since it does not have identity to start with, right? Then I woulf guess you can't map it directly.

Depending on how do you actually use someClass, I can think of the following workarounds:

  • if it is part of an entity, you could try mapping it as component - but then again, you could simply map the contained lists directly in this case
  • if it is simply used to store query results, you could put together a scalar query to return the contents of the two lists, then assemble your objects from the results
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜