-->
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: Caching problems while using one-to-one mapping
PostPosted: Sat Nov 18, 2006 2:56 pm 
Newbie

Joined: Fri Nov 17, 2006 2:14 pm
Posts: 1
Location: Bangalore
Hibernate version: 3.1.3 AND Ehcahe 1.2

Name and version of the database you are using: MS SQL Server 2000

I have a problem with one-to-one mapping. The way I use one-to-one mapping is by using a one-to-one on the parent side and a many-to-one reference on the child side. The problem I face is that while caching the parent entity, the child entity cannot be retrieved from a cache and a query is fired to fetch the child entity inspite of the child entity being cached. I understand that child objects can be retrieved from cache using primary key only, and the parent and child are not related using a primary key because of the one-to-one mapping limitation.

Mapping documents:
Snippets of mapping files are here:

The parent entity is Destination.
<hibernate-mapping
auto-import="true"
default-lazy="true">
<class
name="com.kuldip.search.data.Destination"
table="DESTINATION">
<cache usage="read-only" />
<id name="destinationId">
<column name="DestinationID" />
<generator class="native"></generator>
</id>
...............
<one-to-one
name="alternativePropertyDestination"
class="com.kuldip.domain.alternatives.AlternativePropertyDestination"
property-ref="destination"
fetch="join">
</one-to-one>
</class>
</hibernate-mapping>

The child entity is AltenativePropertyDestination:
<hibernate-mapping
auto-import="true"
default-cascade="none"
default-lazy="true">
<class
name="com.kuldip.domain.alternatives.AlternativePropertyDestination"
table="ALTERNATIVE_PROPERTIES_DESTINATION"
dynamic-insert="true"
dynamic-update="true">
<cache usage="read-only" />
<id
name="id"
type="long"
unsaved-value="null">
<column
name="ID"
sql-type="NUMBER(10)" />
<generator class="native"></generator>
</id>
<many-to-one
name="destination"
column="destinationId"
not-null="true">
</many-to-one>
<property
name="lastUpdated"
type="java.util.Date">
<column
name="LastUpdated"
not-null="true"
unique="false" />
</property>
</class>
</hibernate-mapping>

In the child entity I cannot use destination as the <id> because one-to-one mapping does not support it.

Every time I fetch the parent entity from cache a query is fired to fetch the child entity. This is affecting the performance. Is there any better way to tune one-to-one mapping?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 19, 2006 9:06 am 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
Check out http://www.hibernate.org/162.html
Try having a constrained="true" on the one-to-one side indicating that there would always be a associated object for the one-to-one mapping. Hibernate will then provide a proxy for you in this case.


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.