ManyToOne with where clause

I have some logically deleted entries (i.e. active=false ) that cause problems with my @ManyToOne mapping as more than one result is returned by the join column.

I only need to include entries where active=true , which, as I thought, I could achieve:

 @ManyToOne @NotFound(action = NotFoundAction.IGNORE) @JoinColumn(name = "site_id", referencedColumnName = "site_id", insertable = false, updatable = false) @WhereJoinTable(clause = "active=true") private Site site; 

However, it seems that WhereJoinTable not using hibernate (perhaps its value is only for OneToMany ?), Since active=true not displayed in the generated SQL (logs), and the problem persists.

Can I include a where clause to connect a ManyToOne and how?

+6
source share
2 answers

@WhereJoinTable is not supported using @ManyToOne. There is an error HHH-4335 about an object opened since five years. I don't know about a workaround, except for using the view (in case of read-only access) as indicated in the error report.

+2
source

@JoinColumnOrFormula anotation is a suitable workaround

+1
source

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


All Articles