I am new to HQL and trying to write a query that involves two entities. This is legacy code and adding the @OneToOne
relationship to the FirstEntity
would be a gigantic task.
On the other hand, I can change the firstEntityReference
to have the @OneToOne
.
@Entity
public FirstEntity {
private long firstEntityId;
...
}
And second entity:
@Entity
public SecondEntity {
private long secondEntityId;
/*
* I could Change this to:
* @OneToOne
* private FirstEntity firstEntityReference;
* But not sure if it would help with anything
*/
private long firstEntityReference;
private boolean deleted;
...
}
The question is would it be possible to do something like this query:
select fe.* from FirstEntity fe
left join SecondEntity se on fe.firstEntityId = se.firstEntityReference
where (se is null or se.deleted = 1)
Keep in mind that the root of the query has to be FirstEntity
. I am trying to wrap my head around whether the join is possible here: Join<FirstEntity, SecondEntity> join = ...
but can't figure it out yet.