-->
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.  [ 14 posts ] 
Author Message
 Post subject: List-index properties are not updated if item is deleted
PostPosted: Sun Dec 17, 2006 6:57 pm 
Newbie

Joined: Sun Dec 17, 2006 6:39 pm
Posts: 8
Hi,

I have a list of objects that are indexed using a list-index mapping.

The objects stored in the list have a property, 'sequenceNumber', that is mapped to the column used as the list index.

When I delete from the list and then persist the changes, the objects in the list do not have their 'sequenceNumber' property updated. Hence the database contains different values for 'sequenceNumber' than do my list of objects in memory.

I expected Hibernate to update the 'sequenceNumber' property for all objects in the list. Can hibernate be made to do this or do I have to set it manually or reload the collection?

Many thanks,

Adam.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 7:04 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
list.remove() should definitively do that (ie shifting the subsequents elements indexes)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 7:33 pm 
Newbie

Joined: Sun Dec 17, 2006 6:39 pm
Posts: 8
The List* collection indexes are correct. The list indexes in the database are correct. However, the 'sequenceNumber' properties on the objects contained within the list, have not been updated. (note the objects within the list have not been reloaded, the 'sequenceNumbers' are fine if they are reloaded)


* happens to be list.removeAll() in this case


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 7:37 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
ah
have a look at generated="always" in the reference documentation, that might help

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 8:07 pm 
Newbie

Joined: Sun Dec 17, 2006 6:39 pm
Posts: 8
Sorry, setting generated="always" on the sequenceNumber property does not help.

My code is something like this...

Code:

// in this case, obj.getList() has three elements.

int x = obj.getList().get(0).getSequenceNumber(); // x = 0, hooray!

obj.getList().remove(obj.getList().get(0)); // remove the first one

getHibernateTemplate().saveOrUpdate( obj ); // update

x = obj.getList().get(0).getSequenceNumber(); // x = 1, boohoo!

// x should be '0' :-(



Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 9:01 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
adam77 wrote:
Sorry, setting generated="always" on the sequenceNumber property does not help.

My code is something like this...

Code:

// in this case, obj.getList() has three elements.

int x = obj.getList().get(0).getSequenceNumber(); // x = 0, hooray!

obj.getList().remove(obj.getList().get(0)); // remove the first one

getHibernateTemplate().saveOrUpdate( obj ); // update

x = obj.getList().get(0).getSequenceNumber(); // x = 1, boohoo!

// x should be '0' :-(



May be i am missing something ...but elements in the list are not sorted ..
( you would get the expected results if the results were sorted according to sequence number )

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 9:06 pm 
Newbie

Joined: Sun Dec 17, 2006 6:39 pm
Posts: 8
Sorry, to be more clear....

List before...

x = getList().get(0).getSequenceNumber() // x = 0
x = getList().get(1).getSequenceNumber() // x = 1
x = getList().get(2).getSequenceNumber() // x = 2

then remove first item, do update and we get...

x = getList().get(0).getSequenceNumber() // x = 1
x = getList().get(1).getSequenceNumber() // x = 2

as you can see, the sequenceNumber properties have not changed


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 18, 2006 2:07 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
has the flush operation occured?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 18, 2006 3:22 pm 
Newbie

Joined: Sun Dec 17, 2006 6:39 pm
Posts: 8
I tried a flush but it didn't help.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 18, 2006 4:18 pm 
Newbie

Joined: Sun Dec 17, 2006 6:39 pm
Posts: 8
This seems to be a similar issue...

http://forum.hibernate.org/viewtopic.php?p=2334454


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 18, 2006 9:32 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
are you using mappedBy. Since the fist example works, I would say no.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 18, 2006 11:37 pm 
Newbie

Joined: Sun Dec 17, 2006 6:39 pm
Posts: 8
What is mappedBy? I can't find it in the docs.

I'm using xml mapping files instead of annotations.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 9:14 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I reocmmand you read the reference documentation
http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 21, 2006 12:25 pm 
Newbie

Joined: Tue Sep 26, 2006 8:34 am
Posts: 16
Location: Paris, France
i finally solve my issue which look similar to your's

check http://forum.hibernate.org/viewtopic.php?t=968296


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