0

Hi I am looking for JPA criteria query (Java code) for the following sql

My SQL Query:

SELECT @today := now();

select r.globalid, r.groupid from review r 
left join group ug on r.globalid = ug.globalid 
and r.groupid = ug.groupid  --having problem here???
and @today between r.startdate and r.enddate
where ug.globalid is null

These are two entities named:

  1. Review (ID(Primary Key),GlobalId , GroupID,.....)
  2. Group (ID (Primary Key), GlobalId, GroupID, .....)

in the above two entities there are multiple columns.However,the two columns in both the entities are same they are, globalid and groupid

I would like to join both the tables with the matched columns using criteria query(Java JPA with Hibernate) as there is no entity relationship exists between these two entities I am confused how to join them.

Edit:

This is purely using JPA. Any help is greatly appreciated.

Narayan
  • 5,455
  • 2
  • 37
  • 43
Harry
  • 233
  • 1
  • 5
  • 19
  • Possible duplicate of [Hibernate criteria: Joining table without a mapped association](https://stackoverflow.com/questions/720502/hibernate-criteria-joining-table-without-a-mapped-association) – TheBakker Apr 10 '18 at 20:53
  • AFAIK, criteria can do subquery and not a left join – Narayan Apr 10 '18 at 20:54
  • @Narayan: Can you provide me an example – Harry Apr 12 '18 at 14:17
  • @TheBakker: The question is almost 4 years old. with the new implementations in JPA2.1 I am guessing there might be a solution. – Harry Apr 12 '18 at 14:18
  • @user3854185 : did you look at this answer https://stackoverflow.com/a/2102080/81367 ? – Narayan Apr 12 '18 at 15:18

0 Answers0