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: Caching and order-by clause
PostPosted: Tue Jan 06, 2009 7:30 am 
Newbie

Joined: Fri Dec 19, 2008 8:13 am
Posts: 3
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

NHibernate 2.0.1.4000

Mapping documents:

LineItemVersion.hbm.xml :

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="LSC.LIDB.DVO.LineItemVersion, LSC.LIDB.DVO" table="LINEITEM_VERSIONS">
<id name="Id" column="ID" type="Int32">
<generator class="identity" />
</id>
...
<bag name="ChapterVersions" table="CHAPTER_LINEITEM_VERSIONS" inverse="true" order-by="CHAPTER_VERSION_ID">
<key column="LINE_ITEM_VERSION_ID" />
<many-to-many class="LSC.LIDB.DVO.ChapterVersion, LSC.LIDB.DVO" column="CHAPTER_VERSION_ID"/>
</bag>
</class>
</hibernate-mapping>

ChapterVersion.hbm.xml :

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="LSC.LIDB.DVO.ChapterVersion, LSC.LIDB.DVO" table="CHAPTER_VERSIONS">
<id name="Id" column="ID" type="Int32">
<generator class="identity" />
</id>
...
<list name="LineItemVersions" table="CHAPTER_LINEITEM_VERSIONS">
<key column="CHAPTER_VERSION_ID" />
<index column="LINE_ITEM_VERSION_ORDER"/>
<many-to-many class="LSC.LIDB.DVO.LineItemVersion, LSC.LIDB.DVO" column="LINE_ITEM_VERSION_ID" />
</list>
</class>
</hibernate-mapping>


Right, so I have a many-to-many relationship between ChapterVersion and LineItemVersion. ChapterVersion now has a list of LineItemVersions with an approprite index. This works find.

LineItemVersion has a bag of ChapterVersions, with an order-by attribute set, so when retreived from the database, ChapterVersions come back in order of creation (ascending auto ids). This works fine, when requesting ChapterVersions from a LineItemVersion when the NHibernate Cache is clear.

However, I have created a unit test to test this logic, and when I create the LineItemVersion and ChapterVersions, and save them, they go into the nhibernate cache, and when I request myLineItemVersion.ChapterVersions, no sql is executed, and the order-by clause has no effect. I have fixed the unit tests by clearing the cache between saving and getting the data back out and the ordering works.

However, should I reallly be clearing the cache for the production code if a user creates a new ChapterVersion for example? Seems wrong to me, so I am sure I am approaching this relationship a little wrong.

Hopefully, I have described this issue appropriately to allow some feedback...

Cheers


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.