-->
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.  [ 1 post ] 
Author Message
 Post subject: Trouble initializing sorted set from second level cache
PostPosted: Tue Aug 21, 2007 6:30 pm 
Newbie

Joined: Tue Aug 21, 2007 5:57 pm
Posts: 7
I'm having trouble initializing a (non-lazy) sorted set when the second level cache is enabled.

I have a User object that contains a SortedSet of EmailAccount objects. When accessing the user, with the second level cache enabled, the set appears to be in the incorrect order. The EmailAccount objects implement Comparable by comparing creation timestamps. Using some debugging, the following sequence of method calls happen during a test of a user with three (already persisted) email accounts (ea1, ea2, ea3):

ea1.setId()
ea2.setId()
ea2.setCreationTimestamp()
ea3.setId()
ea3.setCreationTimestemp()
ea2.compareTo(ea3)
ea1.compareTo(ea3)
ea1.compareTo(ea2)
ea1.setCreationTimestamp()

The comparisons are incorrect because ea1 has not had its creation timestamp set from the persistent data before it is used to compare the object.

When I disable the second-level cache, the objects are fully initialized before they are compared and the problem disappears.

I'm using Hibernate 3.2.5, MySQL 5.0.37.

Here's (hopefully) the relevant portions of the mapping docs:
Code:
<class name="mypackage.User" table="Users" lazy="false">
       <cache usage="transactional"/>
   ...
   <set name="emailAccounts" cascade="all-delete-orphan" lazy="false" sort="natural">
      <cache usage="transactional"/>
      <key column="user_id" not-null="true"/>
      <one-to-many class="mypackage.EmailAccount"/>
   </set>
</class>
...
<class name="mypackage.EmailAccount" table="EmailAccounts" lazy="false">
   <cache usage="transactional"/>
        <id name="id" type="long" column="EMAIL_ACCT_ID" unsaved-value="0" >
      <generator class="native"/>
   </id>
   <property name="creationTimestamp" type="timestamp"/>
   ...
</class>


Can anyone shed some light on this situation?

Thanks!


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

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.