-->
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.  [ 2 posts ] 
Author Message
 Post subject: <many-to-one> or <one-to-one> with property-ref
PostPosted: Fri Oct 21, 2005 12:20 am 
Regular
Regular

Joined: Thu Dec 02, 2004 10:42 am
Posts: 54
I am mapping 2 classes with <many-to-one> or <one-to-one> with "property-ref" attribute

Code:
<class name="ClassA">
    <id column="ID" ... >... </id>
    <many-to-one name="b" column="ID" insert="false" update="false: class="ClassB" property-ref="a" />
</class>
<class name="ClassB">
    <many-to-one name="a" column="A_ID" class="ClassA" />
</class>


Then using this HQL: what I expected is NHibernate can just send one query to the DB to fetch the data:
Code:
querystr = "from ClassA A inner join fetch A.b where a.ID = :paramID"


But NHibernate is acctually issuing 2 queries, the first one is what I expected, join fetched both ClassA and ClassB. But the 2nd one is a query to get ClassB AGAIN with condition "ClassB.A_ID = :p0"

If I get rid of "property-ref" in ClassA mapping, that means I need to add a column in ClassA's table named "B_ID", then the HQL can run with one query, but I don't like to change the table or create a View, it's a legacy database, and I am afraid View will be slow.


why this is happening, does Hibernate 3.x solved this already :?:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 7:52 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
The problem with property-refs is that NHibernate keeps track of all objects by their identifier, so it has trouble figuring out whether the object is already loaded when all it has is its property-ref value. So expect a bit slower performance for such a schema. I don't know if Hibernate3 has any workarounds for this. You should try creating the view and evaluating its performance.


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

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.