Hibernate, Persistence and @OneToMany and @ManyToOne annotation issues

I have some problem with the comments of @OneToMany and @ManyToOne.

I have two classes, Suite and SuiteVersion. SuiteVersion is set dependent. So I implemented this in my code:

Suite Class:

@OneToMany(mappedBy = "suite")
@Cascade(CascadeType.DELETE_ORPHAN)
private List<SuiteVersion> listSuiteVersion = new ArrayList<SuiteVersion>();

SuiteVersion Class:

@ManyToOne()
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
private Suite suite;

But I have a problem when I delete a Suite that has SuiteVersion associated. Hibernate does not remove SuiteVersion before Suite.I don’t know why, because I mentioned this in my code:

@Cascade(CascadeType.DELETE_ORPHAN)

This is the i log received when the package was removed:

: SUITE, ID_SUITE =? 13 août 2010 09:40:50 org.hibernate.util.JDBCExceptionReporter logExceptions : SQL: -8, SQLState: 23504 13 août 2010 09:40:50 org.hibernate.util.JDBCExceptionReporter logExceptions GRAVE: : ; FK42895651EA304E6: SUITE_VERSION

.

,

,

P.S: , .

+3
1

, Suite, SuiteVersion. Hibernate SuiteVersion Suite.

, , REMOVE Suite SuiteVersion. , - ( JPA 1.0):

@OneToMany(mappedBy = "suite", cascade = javax.persistence.CascadeType.REMOVE)
@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private List<SuiteVersion> listSuiteVersion = new ArrayList<SuiteVersion>();

, Hibernate JPA.

Hibernate CascadeType.DELETE_ORPHAN - , , Hibernate SuiteVersion, ( SuiteVersion , Suite, , "" ).

, JPA 2.0 (.. Hibernate 3.5+), , Hibernate. orphanRemoval OneToMany ( OneToOne). :

@OneToMany(mappedBy = "suite", cascade = CascadeType.REMOVE, orphanRemoval = true)
private List<SuiteVersion> listSuiteVersion = new ArrayList<SuiteVersion>();

, , .

+2

Source: https://habr.com/ru/post/1759473/


All Articles