Hibernate JPA OneToOne orphan removal still not working with 4.2.7 / 4.3.0.CR1

After reading JPA 2.0 / Hibernate and "orphanRemoval": simply replacing the entity does not delete the old file and the corresponding ticket https://hibernate.atlassian.net/browse/HHH-6484 , I assumed that this was (finally) fixed in versions 4.2. 7 and 4.3.0.CR1.

However, trying

...
entityManager.getTransaction().begin();
Point point = entityManager.find(Point.class, pointId);
point.setPost(null);
entityManager.getTransaction().commit();
...

Where

public class Point {
    ...
    @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
    private Post post;
    ...
    public void setPost(Post post) {
        this.post = post;
    }
}

still does not make Hibernate return an DELETESQL statement for the target Post.

So, has the problem @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)been fixed or not? and if so, how can I get the orphans to be removed? Many thanks!

EDIT: After reading your answer, I noticed that I (erroneously) did not indicate what is fetch=FetchType.LAZYin my comparison above.

+3
1

, , , , . null, .

(.. null) Hibernate 4.1.8, , , Post. Post , , , .

4.2.7, , , , ​​ 4.2.7.

Update:

, Fetch persist, , .

+2

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


All Articles