Hibernate, Persistence and @OneToMany and @ManyToOne annotations problems?

That's because you're NOT cascading the REMOVE operation from Suite to SuiteVersion To obtain the desired result, you need something like this (assuming you're using JPA 1.0).

But I have some problem when I delete a Suite whose have SuiteVersion associated. Bernate don't delete SuiteVersion before Suite. That's because you're NOT cascading the REMOVE operation from Suite to SuiteVersion.To obtain the desired result, you need something like this (assuming you're using JPA 1.0): @OneToMany(mappedBy = "suite", cascade = javax.persistence.CascadeType.

REMOVE) @Cascade(org.hibernate.annotations.CascadeType. DELETE_ORPHAN) private List listSuiteVersion = new ArrayList(); I used fully qualified names to clearly show the bernate specific and the standard JPA annotations here. The bernate specific CascadeType.

DELETE_ORPHAN is something else, it is used to tell bernate to delete a specific SuiteVersion if you remove it from the collection (without it, the SuiteVersion record would be updated to remove the link to the parent Suite but would remain in the table, being thus an "orphan"). Note that if you are using JPA 2.0 (i.e.5+), there is now a standard way to deal with orphan records i.e. Without using the bernate specific annotation.

You can specify an orphanRemoval option in your OneToMany (and OneToOne) association. Like this: @OneToMany(mappedBy = "suite", cascade = CascadeType. REMOVE, orphanRemoval = true) private List listSuiteVersion = new ArrayList(); But this goes beyond this question as this is actually not what you're looking for.

You are right. DELETE_ORPHAN just works when you remove The associated Entity from The collection. (+1) – Arthur Ronald F D Garcia Aug 13 '10 at 14:59 Thank you, this help me a lot.

But I have juste move to jpa 2.0 before I learn your post. At the end of your post you speak about a new standard way to deal with orphan. Can you explain me this new way to deal this orphan?

– Delildor Aug 13 '10 at 15:36 @Delildor: You're welcome. Regarding orphans with JPA 2.0, see my update. – Pascal Thivent Aug 13 '10 at 16:17.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions