-->
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.  [ 6 posts ] 
Author Message
 Post subject: property-ref not loaded from cache ?
PostPosted: Thu Apr 28, 2005 10:02 am 
Beginner
Beginner

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

Mapping documents:

I have a bidirectional one-to-one mapping between Group and a GroupRSSChannel realized with many-to-one on the Group and one-to-one + property-ref="group" on the GroupRSSChannel.

The mappings are below:

Code:
<subclass name="GroupRSSChannel" discriminator-value="GROUP">
   <one-to-one name="group"
      property-ref="rssChannel"
      class="Group"
      />
</subclass>


and in Group mapping:

Code:
<many-to-one
        name="rssChannel"
        class="GroupRSSChannel"
        unique="true"
        cascade="all"
      >       
       
        <column name="rss_channel_id" />
</many-to-one>


My problem is that if I make both classes cachable, when I list the groups Hibernate will issue a select from Group for each propertyRef from the GroupRSSChannel. If I remove the bidirectionality (thus the propertyRef statement) everything works as expected, groups come from the query cache, no statement is issued to the DB.

Am I doing something wrong (most probably), or this is the expected behavior (one select from db for each property-ref) the property-ref shouldn't come (or can't be obtained) from the cache ?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 28, 2005 5:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
second-level caching based on property-refs has not yet been implemented. Currently, the second-level cache exclusively uses the id value to cache the entities.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 29, 2005 4:04 am 
Beginner
Beginner

Joined: Thu Jun 10, 2004 6:52 am
Posts: 29
Hmm, good to know, thanks. I'll try to avoid this in the future, I didn't know.

Which are the best practices though when you need let's say three bidirectional one-to-one relationships from User to Address, let's say billingAddress, homeAddress and deliveryAddress ? I've allways solved this with fk from user to address and created three "fake" sublcasses for each type of address and referenced the user back from address with a property-ref but this is clearly and simply not the way to go when you want caching to work as expected (if you need to list 10 users on a page you'll get 30 selects for displaying that page mistake which I won't repeat in the next 20 years).

The first thing that comes to mind to fix this is proxying the Address with an interface so that it won't be loaded at user load unless specified ?

PS. I promiss I won't hack again. I didn't listen to hibernate docs which call one-to-one by FK practice "hacking" but I really didn't know how to solve this problem otherwise. With one-to-one with primary key you can map only one user to one address.

thanks again


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 29, 2005 8:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
If you are using Hibernate3, try out the SpecialOneToOneType. It was intended for exactly this purpose. It looks something like:

Code:
<class name="User" ...>

    <one-to-one name="homeAddress" constrained="false" ...>
        <formula>userId</formula>
        <formula>'HOME'</formula>
    </one-to-one>

    <one-to-one name="mailingAddress" constrained="false" ...>
        <formula>userId</formula>
        <formula>'MAILING'</formula>
    </one-to-one>

</class>


Basically, it is just another way to twist a many-to-one into a one-to-one.


Top
 Profile  
 
 Post subject: humm, thanks. nothing for 2.1.8 ?
PostPosted: Fri Apr 29, 2005 9:18 am 
Beginner
Beginner

Joined: Thu Jun 10, 2004 6:52 am
Posts: 29
humm, thanks. there's no workaround for for 2.1.8 ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 10, 2007 11:10 am 
Newbie

Joined: Mon Dec 10, 2007 7:03 am
Posts: 1
steve wrote:
second-level caching based on property-refs has not yet been implemented. Currently, the second-level cache exclusively uses the id value to cache the entities.


Hi steve,
Has second-level caching based on property-refs been implemented in 3.2.5.ga? (many-to-one)


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