Hi All,
I am new to Hibernate using Hibernate3 with annotations. I have a very wierd problem in my code. I am using @OneToMany and @ManyToOne mapping between 2 classes. The logic is that one Collection can have many Files and Many Files can belong to one Collection. The code is like this:
Code:
In class Collection:
@OneToMany (cascade=CascadeType.REMOVE, mappedBy="dataCollection")
private List<CollectionFilesMapping> filesList;
In class File:
@ManyToOne(targetEntity = DataCollection.class)
@JoinColumn (name="Collection_ID")
private DataCollection dataCollection;
But the Cascade simply does not seem to work :(
I tried out a number of changes in the properties but in vain.
I get an exception like this:
Cannot delete or update a parent row: a foreign key constraint fails (`files`, CONSTRAINT `FK263465956066C15` FOREIGN KEY (`Collection_ID`) REFERENCES `collection` (`Collection_ID`))
I have other @ManyToMany mapping in this class Collection and that works fine.
Any help would be greatly appreaciated!
Thanks in advance.