-->
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.  [ 4 posts ] 
Author Message
 Post subject: Orphans not deleted on bidirectional association (MySql)
PostPosted: Mon Jun 06, 2011 4:46 am 
Newbie

Joined: Tue Nov 04, 2008 3:07 am
Posts: 9
Hi all,
I have Car hibernate object bound to cars table; each car has its speedometer readings (List of date and speedometer value) bound to "speedometers" table,
When removing speedometer value from the car speedometer list and persisting the Car - speedometer is not deleted from the DB (save is working ok)
What am I doing wrong?
Thank you very much for your help!

CarSpeedometer object:
Code:
   
@ManyToOne
@NotNull
@JoinColumn(name="car_plate")
private Car car;


Car object:
Code:
@OneToMany(mappedBy="car",cascade={CascadeType.ALL})   
@LazyCollection(LazyCollectionOption.FALSE)   
@JoinColumn (name = "car_plate")
@org.hibernate.annotations.Cascade(value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
@OrderBy("speedometerDate")
private List<CarSpeedometer> speedometers = new ArrayList<CarSpeedometer>();


Top
 Profile  
 
 Post subject: Re: Orphans not deleted on bidirectional association (MySql)
PostPosted: Tue Jun 07, 2011 1:18 am 
Newbie

Joined: Wed Jun 24, 2009 9:10 pm
Posts: 10
Remove @JoinColumn from speedometers property.


Top
 Profile  
 
 Post subject: Re: Orphans not deleted on bidirectional association (MySql)
PostPosted: Wed Jun 08, 2011 1:47 pm 
Newbie

Joined: Tue Nov 04, 2008 3:07 am
Posts: 9
I removed @JoinColumn annotation from speedometers property - didnt help.
Any advice will be appreciated!


Top
 Profile  
 
 Post subject: Re: Orphans not deleted on bidirectional association (MySql)
PostPosted: Fri Jun 10, 2011 4:33 am 
Newbie

Joined: Tue Nov 04, 2008 3:07 am
Posts: 9
Ok I think I got it, the collection reference was changed.

What happened is:

I am using Spring MVC with Form object for UI rendering

Here is flow of usage:
Controller ---> get the Truck object---> copy it to the FORM object ---> render it
User will edit the data ---> Data is copied to the FORM object ---> back to the Controller ---> get the data from the form as new object with the same ID ---> save it

Probably the truck Object lost the collection reference and didn’t invoke any delete statements.
So for example this won't work either:
Person -> phones
Person person = getPerson();
List phones = cloneToNewList(person.getPhones());

phones.remove(0);
phones.add(new phone(' 442376283-78257')); // :)
person.setPhones(phones);
persist(person);
//RESULT : new phone added but new phones won't be deleted.

Why does hibernate cares about the collection reference is not so clear when equality can be figured out thru the equals method.


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