Hi All,
I'm having a problem using Hibernate ordered lists and would appreciate any help you can provide.
I've also posted this problem on the hibernate forum but have not had much luck: https://forum.hibernate.org/viewtopi...42141#p2442141
The configuration:
An AlbumGroup has a collection of Albums. This is a uni-directional relationship.
The problem: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>
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:
My test code: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
The Spring mappings are pretty standard so I realise that this is most probably a hibernate issue but would greatly appreciate any help.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,
Nim


Reply With Quote
