-->
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.  [ 3 posts ] 
Author Message
 Post subject: problem with ordered list
PostPosted: Tue Mar 01, 2011 2:52 pm 
Newbie

Joined: Tue Sep 28, 2010 7:31 pm
Posts: 5
Hi All,

I'm having a problem with an ordered list and would greatly appreciate any help.

Configuration:
An AlbumGroup contains a list of Albums. It is not a bi-directional relationship.

Code:
   <list name="albums" cascade="all" lazy="false" inverse="false">
      <key column="ALBUMGROUP_ID" not-null="true"/>
      <list-index column="ALBUM_POSITION"/>
      <one-to-many class="com.nim.domain.Album"/>
   </list>



The problem:
I add a new Album to a new AlbumGroup and saved the AlbumGroup. After saving the AlbumGroup, the album's position (list-index) was 4. I.e. there were 4 elements in the album List: null, null, null, myAlbum. My debug statements prior to saving the AlbumGroup using hibernate shows that there was only 1 Album in the albums list.

The sql trace shows that the Album is saved correctly then the index is updated 3 times:
Code:
Hibernate: update ALBUM set ALBUMGROUP_ID=?, ALBUM_POSITION=? where ALBUM_ID=?
TRACE - LongType                   - binding '1' to parameter: 1
TRACE - IntegerType                - binding '0' to parameter: 2
TRACE - LongType                   - binding '1' to parameter: 3
Hibernate: update ALBUM set ALBUMGROUP_ID=?, ALBUM_POSITION=? where ALBUM_ID=?
TRACE - LongType                   - binding '1' to parameter: 1
TRACE - IntegerType                - binding '1' to parameter: 2
TRACE - LongType                   - binding '1' to parameter: 3
Hibernate: update ALBUM set ALBUMGROUP_ID=?, ALBUM_POSITION=? where ALBUM_ID=?
TRACE - LongType                   - binding '1' to parameter: 1
TRACE - IntegerType                - binding '2' to parameter: 2
TRACE - LongType                   - binding '1' to parameter: 3
Hibernate: update ALBUM set ALBUMGROUP_ID=?, ALBUM_POSITION=? where ALBUM_ID=?
TRACE - LongType                   - binding '1' to parameter: 1
TRACE - IntegerType                - binding '3' to parameter: 2
TRACE - LongType                   - binding '1' to parameter: 3



My test code:
Code:
        albumGroup = createAlbumGroup();
   albumGroupDao.save(albumGroup);
   assertTrue("albums size:" + albumGroup.getAlbums().size(), albumGroup.getAlbums().isEmpty());
      
   album = createAlbum();
   albumGroup.getAlbums().add(album);
   assertTrue("albums size:" + albumGroup.getAlbums().size(), albumGroup.getAlbums().size() == 1);
   albumGroupDao.save(albumGroup);


I am using Hibernate version 3.2.7.ga and hsqldb.

Thanks in advance for your help.
Nim


Top
 Profile  
 
 Post subject: Re: problem with ordered list
PostPosted: Wed Mar 02, 2011 7:09 am 
Newbie

Joined: Tue Sep 28, 2010 7:31 pm
Posts: 5
webvantage wrote:
I think you have any server problem. Try to check that because I think there is no problem in the code.


Thanks for your reply. I'm not sure how to check if it is a server problem - I'm running a junit test on eclipse. I've enabled all the debug message that I can think of.


Top
 Profile  
 
 Post subject: Re: problem with ordered list
PostPosted: Wed Mar 02, 2011 9:51 am 
Newbie

Joined: Tue Sep 28, 2010 7:31 pm
Posts: 5
webvantage wrote:
I think you have any server problem. Try to check that because I think there is no problem in the code.


I think you were right! It must have been something to do with my environment - all is working this morning after a reboot and a rebuild.

Thanks for your help.

Cheers,
Nim


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