-->
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: problem with one-to-one null value caching
PostPosted: Thu Jun 30, 2005 1:18 pm 
Newbie

Joined: Wed Jun 29, 2005 10:41 pm
Posts: 3
Location: New Jersey
Given simple schema below

Account (1 <--> 0,1) AccountUKData, and they share same primary key. We tested repeately, and getting same result:

1) when first time load Account, hibernate goes to db to retrieve UKData, then cache the Account. Understood.

2) second time we try to load the same account, hibernate returns it from to the cache, [b]but it also goes to db again!![/b], fruitlessly trying to retrieve UKData.

We thought hibernate should be able to know that it's been initialized before, store such info in the cache, so next time it should not intiate the db trip again. It does this for collection associations.

We saw a note in "Changes in version 1.2.1 (31.12.2002)": "fixed a bug caching null-valued one-to-one associations", not sure whether this is the same one just we did something wrong or not.

Any insight will be appreciated.

We are using Hibernate v3.0.5, and EhCache.
Mapping files below,

Account:
<class name="AccountDO" table="ACCOUNT" schema="ACCOUNT">
<cache usage="read-write"/>
<!-- primary key-->
<id name="accountId" column="ACCOUNT_ID" type="int">
<generator class="identity"/>
</id>
....
<one-to-one name="accountUKData"
class="AccountUKData"
cascade="all-delete-orphan"
fetch="join"
/>
...
</class>

AccountUKData:
<class name="AccountUKData" table="ACCOUNT_UK_DATA" schema="ACCOUNT" lazy="true">
<!-- primary key-->
<cache usage="read-write"/>
<id name="accountId" column="ACCOUNT_ID" type="int">
<generator class="foreign">
<param name="property">account</param>
</generator>
</id>
....

<one-to-one name="account"
class="AccountDO"
constrained="true"
/>
</class>

just using session.load(AccountDO.class, new Integer(x)) to load the account.

Thanks!

--Woody


Top
 Profile  
 
 Post subject: Mapping a "one-to-zero-or-one" relationship
PostPosted: Tue Oct 18, 2005 4:42 pm 
Newbie

Joined: Wed Oct 06, 2004 10:34 am
Posts: 16
Location: Teresina - PI - Brasil
I've been searching a way to do a lazy a "one-to-zero-or-one" relationship in Hibernate and I finally found a way to do it using many-to-one with unique="true". See example below:

Association: Person [1 <--> 0..1] Note

Code:
<class name="Person" table="person">
   <id name="id" column="id" type="int" unsaved-value="-1">
       <generator class="sequence">
           <param name="sequence"father_id_seq</param>
       </generator>
   </id>
   <property name="name" type="string"/>
   <many-to-one name="note" class="Note" column="id"
                unique="true" insert="false" update="false"
                cascade="all"/>
</class>

<class name="Note" table="note">
   <id name="id" column="id" type="int" unsaved-value="-1" >
       <generator class="foreign">
           <param name="property">owner</param>
       </generator>
   </id>
   <property name="note" type="string"/>
   <one-to-one name="owner" class="Person" constrained="true"/>
</class>



Observe that column "id" is used twice in Person mapping.

_________________
Regis Pires


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.