-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: mapping joined table field
PostPosted: Wed Jun 22, 2005 7:29 pm 
Newbie

Joined: Fri May 27, 2005 3:19 pm
Posts: 18
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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.