I have a problem when trying to delete a child object from a parent object which has a collection of this child object. I've done a lots of googling and have tried many combination of solutions, it still doesn't work. I am really confused at this point. Please help me!
For example:
For the Parent "Collection" object, I have
Code:
@OneToMany(cascade=CascadeType.ALL, mappedBy="collection", fetch=FetchType.EAGER)
@Cascade(value={org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
public Set<Book> getBooks() {
return books;
}
For the Child "Book" object, I have
Code:
@ManyToOne
@OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)
@JoinColumn(name="COLLECTION_ID", nullable=false, insertable=true, updatable=true)
public Collection getCollection() {
return collection;
}
I am using a Flex UI client front end talking to Java backend. All of the following JUnit test (w/o running Flex) are fine (in terms of cascading deleting and adding):
(1) remove Collection
(2) add Book into Collection
(3) remove Book from Collection
The problem appears when I try to remove a Book from Collection object when running Flex UI client frontend, through calling Hibernate save(Collection collection), (3) fails with no exception being thrown; the book object supposed to get deleted still alive in the database!! But (1) and (2) still work fine.
Your enlightenment is highly appreciated!!
baffled hibernate newbie....
Hibernate version:3.2.5.ga
Name and version of the database you are using:MySQL 5