Named query when property is an object?

I would like to make this request in JPA:

SELECT * FROM `happyDB`.`users` U WHERE U.party_as_user =1 AND U.party_party_id =2

This works fine, but my problem is that I Partyonly have an object, not an id, and I can't get it to work.

In Users-entity, where I am trying to execute a named request, I have the following:

@JoinColumn(name = "pary_party_id", referencedColumnName = "party_id")
@ManyToOne
private Party partyId;

@Column(name = "party_as_user")
private Boolean partyAsUser;

I tried to implement it as an object with dotted notation, but this does not work:

@NamedQuery(name = "Users.findByPartyAsUser", query = "SELECT u FROM Users u WHERE u.partyAsUser = :partyAsUser AND u.partyId.partyId = :partyId")

The object Partyhas a property called partyId, but it does not work. Is there any solution for this, or do I need to add one property to the User-bean like private int partyIDand fill it every time a new one is Partyinserted into Users?

Thanks for the help! Sami Nurmi

+3
source share
1

JPA,

SELECT u FROM Users u WHERE u.partyAsUser = :partyAsUser AND u.party  = :party

Party party = new Party(id);
query.setParameter("party", party);

, , , ,

SELECT u FROM Users u WHERE u.partyAsUser = :partyAsUser AND u.party.id  = :id

SQL-, SQL , .

+9

All Articles