I apologize again for this question. I am very surprised how sleep mode works, it is really great. I did not think that this would do it all automatically, and I really was not even sure what I was trying to ask. When I answered the comments, I began to refine this question in my head and was able to then find the answer I was looking for. Thanks to everyone who helped.
Answer: hibernate does this automatically.
Suppose your database table A has a primary key id, and table B has a primary key called a_id that refers to table A.
So, you create the following classes (in abbreviated form):
public class A { private String aProperty;
Then map them like this:
<hibernate-mapping> <class name="A" table="a" catalog="testokdelete"> <id name="id" type="java.lang.Integer"> <column name="id" /> <generator class="identity" /> </id> <property name="aProperty" column="a_property"/> <joined-subclass name="B" table="b"> <key column="a_id"/> <property name="bProperty" column="b_property"/> </joined-subclass> </class> </hibernate-mapping>
And you can return objects A and B with a simple query "from A", as in the following code:
Query query = session.createQuery("from A"); List<Object> objects = query.list(); for (Object object: objects) { System.out.print("A property: "); System.out.print(((A)object).getAProperty()); System.out.print(", B property: "); System.out.println( (object.getClass() == B.class) ? ((B)object).getBProperty() : "not a B"); }
All he does is return a list of objects using the query "from A", and then scan them, printing aProperty from our class A, and if the class is of type B, bProperty from our class B.
The sleep request in this case is automatically polymorphic and, if necessary, will give you object B.
Boden
source share