-->
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.  [ 6 posts ] 
Author Message
 Post subject: Bi-directional List not re-ordering and duplicated position
PostPosted: Fri Sep 19, 2008 12:13 pm 
Beginner
Beginner

Joined: Wed Aug 27, 2003 3:46 am
Posts: 34
Location: Taiwan
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: hibernate-3.2.5

Mapping documents:
Code:
  <class name="Account">
    <list name="albums" cascade="save-update" inverse="false">
      <cache usage="nonstrict-read-write"/>
      <key column="accountId" not-null="true" update="false"/>
      <list-index column="position"/>
      <one-to-many class="Album"/>
    </list>
  </class>

  <class name="Album">
    <cache usage="nonstrict-read-write"/>
    <id name="id" column="id" type="int">
      <generator class="increment"/>
    </id>
    <many-to-one name="account" column="accountId" not-null="true" insert="false" update="false"/>
  </class>

This is my mapping file
An account has a list of Album
When an album is deleted , the POSITION column is not re-ordering.
When an new Album is inserted , the POSITION value will equal the max.

If Account acc has Albums 0,1,2,3
If album0 is removed , the POSITION is still 1,2,3 (not 0,1,2)
If a new album is appended , the POSITION becomes 1,2,3,3
"3" is duplicated !!!

It seems the problem has been proposed many times , different people have different setting , but I cannot find a working solution...

Can some body help me ! thank you very much....


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 19, 2008 4:33 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
smallufo,

This feature is still somewhat confusing to implement, as of Hibernate 3.2.2.
And the documentation doesn't help much.

But coincidentally, I wrote an article with an example very similar to your Account-Albums case. Mine is Singer-Albums, and it presents a complete example on how to implement a bidirectional list.
Check it out and tell me what you think.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 19, 2008 4:38 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
sorry, double post :)

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 20, 2008 4:22 am 
Beginner
Beginner

Joined: Wed Aug 27, 2003 3:46 am
Posts: 34
Location: Taiwan
gonzao_diaz wrote:
smallufo,

This feature is still somewhat confusing to implement, as of Hibernate 3.2.2.
And the documentation doesn't help much.

But coincidentally, I wrote an article with an example very similar to your Account-Albums case. Mine is Singer-Albums, and it presents a complete example on how to implement a bidirectional list.
Check it out and tell me what you think.


Hi
Your config is almose the same with mime ... except :
Code:
Yours :
<list name="albums" lazy="true" cascade="all">


Code:
Mine :
<list name="albums" cascade="save-update" inverse="false">

I didn't append "delete" or "delete-orphan" to cascade , because I want to manually delete a album.

Code:
Yours :
<key column="SINGER_ID" not-null="true"/>


Code:
Mine:
<key column="accountId" not-null="true" update="false"/>


I have an additional update="false" attribute here.
I am not sure what it is here , I saw many posts/configs with it.


Is your code able to successfully re-order the POSITION here ?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 20, 2008 5:04 am 
Beginner
Beginner

Joined: Wed Aug 27, 2003 3:46 am
Posts: 34
Location: Taiwan
I try to remove update="false"
<key column="accountId" not-null="true" update="false"/>
becomes :
<key column="accountId" not-null="true"/>

It worked!
The list POSITION can be successfully re-ordered.

BUT , every time I insert a list of objects , I noticed Hibernate first insert and then update...
If I insert 100 albums , there will be 200 SQL commands executed.
I feel this is a very redundent SQL command (and time comsuming)...
Is there any way to prevent this ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 14, 2008 7:28 pm 
Newbie

Joined: Tue Jan 22, 2008 10:10 pm
Posts: 1
gonzao_diaz wrote:
But coincidentally, I wrote an article with an example very similar to your Account-Albums case. Mine is Singer-Albums, and it presents a complete example on how to implement a bidirectional list.
Check it out and tell me what you think.


gonzao_diaz, I get a 404 on the link you provided. Although after a bit of poking around, I think the proper url is http://hibernar.org/articulos_en/bidire ... _lists.php

_________________
Carlos Macasaet
http://www.carlos-m.net/


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