Hibernate version: 3.0.5
Mapping documents:
<class name="A" table="a">
<id name="itemid" column="itemid" type="java.lang.Long">
<generator class="native" />
</id>
....................... other properties
<set name="childrenA" cascade="all-delete-orphan"
inverse="true" lazy="true" batch-size="10">
<key column="relationid" />
<one-to-many class="A" />
</set>
<many-to-one name="parentA" cascade="none"
outer-join="false">
<column name="relationid" not-null="false" />
</many-to-one>
<many-to-one name="b" class="B"
not-null="true">
<column name="contentid" />
<column name="status" />
</many-to-one>
</class>
than class b has many-to-one to c, and than c to d and to e
Code between sessionFactory.openSession() and session.close():
Query q = hSession.createQuery("from A a join a.b.c.d d where "+
" a.b.c.e.userid= :userid " +
" and a.excluded=0"+
" and a.b.status= :status and a.lvl= :lvl");
q.setString("status",status);
q.setString("userid",userid);
q.setString("lvl",lvl);
Iterator pairs = q.list().iterator();
while(pairs.hasNext()) {
Object[] pair = (Object[]) pairs.next();
A a= (A)pair[0];
D d= (D)pair[1];
....................
....................
}
Name and version of the database you are using:
MSSQL2000
What I am trying to do is to have D.value mapped within A to avoid 2 selects. In this example only one select will be generated and query returns two objects.
However, you will see from mapping Class A it has childrenA which are many-to-one to A. So if I am goint to call a.getChildrenA than I will have an array of As returned to me, but to get associated D objects I would have to access it through a.getB.getC.getD.getValue and thsi will create two more selects. I was thinking that to boid it I can map this D.value in class A, any ideas how to do it? Or maybe there is a better way.
Thank you!
|