Announcement Announcement Module
Collapse
No announcement yet.
problem with hibernate ordered list Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • problem with hibernate ordered list

    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.

    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);
    The Spring mappings are pretty standard so I realise that this is most probably a hibernate issue but would greatly appreciate any help.

    I am using Hibernate version 3.2.7.ga and hsqldb.

    Thanks,
    Nim

  • #2
    Hi...

    I think this was an environment problem on my side. All seems to work this morning after a reboot and a rebuild.

    Cheers,
    Nim

    Comment

    Working...
    X