Hibernate Books

All times are UTC - 5 hours [ DST ]

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: How to remove soft deleted entities in associations
PostPosted: Mon Jan 30, 2017 9:01 am 

Joined: Mon Jan 30, 2017 7:59 am
Posts: 1
Hello everyone.
In my task I can't delete rows from DB, instead use boolean column "deleted".
All "select" queries with "where deleted = false" solved my problem.

But what I can do wtih relationship table?
Example we have "board" and "window" entity and "boards_windows" relationship table.
In "board" i have mapping to "window", and Hibernate mapping all rows(windows) although I need only those who "deleted = false".


 Post subject: Re: option: 'delete', instead real deletion
PostPosted: Tue Jan 31, 2017 4:18 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1532
Location: Romania
You need to use the @JoinFormula annotation so that you provide the deleted = true condition.

Considering that you mapped the board_window using a link entity, BoardWindow which has 2 @ManyToOne associations, one to Board and one to Window, and that the BoardWindow.

@ManyToMany(fetch = FetchType.LAZY)
    "( SELECT bw.window_id FROM boards_windows bw WHERE bw.board_id = id and bw.deleted = false )"
private List<Window> windows = new ArrayList()<>;

Check out this article for more details on how @JoinFormula works.

If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.