I’m reading hibernate reference, they’re two elements in Hibernate: <join><any>. After reading it, I don’t know what the reference is talking about.
I don’t understand when to use join/any, what kind of scenarios are they suitable for? For <join/>: when setting “fetch”, when will hibernate use inner join, when will use outer join, when will use select? Which tables which columns are used? And for the example hibernate reference provided, it said:
<join table=”ADDRESS”> <key column=”ADDRESS_ID”/> <property name=”address”/> <property name=”zip”/> <property name=”country”/> </join>, then which column is used to join these two tables?
When setting fetch for <join>, it said:
fetch (optional – defaults to join): If set to join, the default, Hibernate will use an inner join to retrieve a <join> defined by a class(My question: Would anybody please give me an example to say: which is this class?) or its superclasses((My question: Would anybody please give me an example to say: which is this class?) ) and an outer join for a <join> defined by a subclass((My question: Would anybody please give me an example to say: which is this class?) ). If set to select then Hibernate will use a sequential select for a <join> defined on a subclass((My question: Would anybody please give me an example to say: which is this class?)), which will be issued only if a row turns out to represent an instance of the subclass((My question: Would anybody please give me an example to say: which is this class?)). Inner joins will still be used to retrieve a defined by the class and its superclasses((My question: Would anybody please give me an example to say: which is this class?) ).
In other words, I want to know what are all the classes said below:
fetch (optional – defaults to join): If set to join, the default, Hibernate will use an inner join to retrieve a <join> defined by a class or its superclasses and an outer join for a <join> defined by a subclass. If set to select then Hibernate will use a sequential select for a <join> defined on a subclass, which will be issued only if a row turns out to represent an instance of the subclass. Inner joins will still be used to retrieve a <join> defined by the class and its superclasses.
For <any>, what kind of scenarios is it suitable for?, would u please explain how it works? Is there anybody providing example and explaining this to me? Thanks.
<join>is used to map one class two 2+ tables which have a one-to-one association over the primarykey/id<any>is used to map a polymorphic reference e.g. a contact can reference a User or a Company it belongs to. So it uses two columns: one the id of Company/User and a second to store the type of the reference e.g. “user” or “company”. The advantage is that it knows the type (and table) of the referenced entity without the need to look into all possible tables