-->
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.  [ 5 posts ] 
Author Message
 Post subject: Update collection in Hibernate
PostPosted: Sat Feb 06, 2010 12:08 pm 
Newbie

Joined: Sat Feb 06, 2010 11:25 am
Posts: 3
Hello
I've got the following problem: I have class Product , and the list(ArrayList) of objects Feature (class Feature) in this class This list is mapped by @OneToMany(fetch = FetchType.EAGER,cascade = CascadeType.ALL ) Class Feature is not connected to class Product by any relationship. So connection is singledirectional
Hibenate creates a table "prduct_feature" for associating primary keys from both tables
I save class Product by:
Code:
getHibernateTemplate().save(product);

In this case everything saves properly, But if i try to update the product i will meet the following problem:
for example i've got the following lines in table Features: 1 2 3 They all belongs to the same product - product1
if i change 3 to 4 and perform :
Code:
getHibernateTemplate().update(product1);

i will get the following lines in my Features table - 1 2 3 1 2 4 => it means that everytime i update my product i've got new Features list for it
So, i can't understand the reason of such behaviour
Please tell me how can i solve such problem, or is it possible at all? Thanks...


Top
 Profile  
 
 Post subject: Re: Update collection in Hibernate
PostPosted: Mon Feb 08, 2010 4:00 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
How do you change 3 to 4 exactly ?
Can you please attach your source code.


Top
 Profile  
 
 Post subject: Re: Update collection in Hibernate
PostPosted: Tue Feb 09, 2010 11:50 am 
Newbie

Joined: Sat Feb 06, 2010 11:25 am
Posts: 3
I've found the reason of the problem
It was my mistake
Thanks!


Top
 Profile  
 
 Post subject: Re: Update collection in Hibernate
PostPosted: Wed Feb 10, 2010 8:50 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Well, what was the mistake???

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Re: Update collection in Hibernate
PostPosted: Wed Feb 10, 2010 5:44 pm 
Newbie

Joined: Sat Feb 06, 2010 11:25 am
Posts: 3
Every time while editing Product the new instance of Feature was created
The code is not mine, so i had no idea about the reasons of such behaviour


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