Thread: how to put condition for child object in case of @ManyToOne join in hibernate

Forum : Hibernate Core and Annotations.   26 Feb, 2019 11:53
User Image
rahul9835

Newbie

Joined: 4 Jul, 2017

Points: 125

Threads: 10

Posts: 42

how to put condition for child object in case of @ManyToOne join in hibernate

| Quote Date : 26 Feb, 2019    Views:212    



@Entity    
public class Contact{
    @id
    private long id;
    @ManyToOne
    @JoinColumn(name = "account_id")
    private Account account;}

Along with contact object i want to fetch account object only if account.deleteFlag=false is there, how to do please tell me. in case of @OneToMany relation @where Annotation is there but for @ManyToOne relation i got solution like @JoinFormula but it is not working.



Comments

User Image
Sriman

Member

Joined : 15 Jul, 2016

Points : 1020

Threads: 645

Posts: 207

Re: how to put condition for child object in case of @ManyToOne join in hibernate

Reply Date : 5 Mar, 2019

You can try this.


@ManyToOne
@JoinColumn(name = "account_id")
@JoinForumla("(SELECT ACCOUNT NO FROM ACCOUNT A WHERE A.CONTACT_ID = id WHERE A.STATUS = 'A')")
private Account account;}

Load More

No More Comments