-->
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.  [ 3 posts ] 
Author Message
 Post subject: one-to-one property-ref and 2'nd level cache
PostPosted: Thu May 18, 2006 3:20 am 
Beginner
Beginner

Joined: Thu Jun 10, 2004 6:52 am
Posts: 29
Hibernate version:3.1.2

I've put this problem long ago (h 2.1.8) and I don't know if there is a solution to it or not.

I have a bidirectional one-to-one A-B relationship through property-ref (FK, I cannot model it through shared PK way (or can I ?) because A can have a B or not, they can live and have a meaning separately). The problem is that it doesn't work with the 2'nd level cache. When listing no matter what As or Bs, I get a select for the property-ref for each item in the list while I'd expect to get it from the cache.

Is there a solution to this ? I'm sorry I've looked all around the forums and found only unclear or "not implemented" responses.

Please see this

http://forum.hibernate.org/viewtopic.ph ... yref+cache

for the other post.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 18, 2006 6:38 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
dorel wrote:
I have a bidirectional one-to-one A-B relationship through property-ref (FK, I cannot model it through shared PK way (or can I ?) because A can have a B or not, they can live and have a meaning separately).

You can have a PK-to-PK zero-or-one-to-zero-or-one bidirectional mapping by specifying it as many-to-one unique="true" in both directions.

The reason your cache (and most significantly, your session cache: the 2nd level cache is less important for this sort of thing) isn't getting hit is probably down to using a foreign key at one end. I'm not sure, but switching to many-to-one on PKs should improve cache hits.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 19, 2006 1:16 am 
Beginner
Beginner

Joined: Thu Jun 10, 2004 6:52 am
Posts: 29
tenwit wrote:
You can have a PK-to-PK zero-or-one-to-zero-or-one bidirectional mapping by specifying it as many-to-one unique="true" in both directions.


Brilliant. It works. I'll rate.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.