0

I have two entities Outlet and Report.They are not connected in Entity class. I want Reports even when outlet id is not present. Following is the query I am writing but its behaving like inner join.

@Query("Select rep,out.area.area_name from Report rep left join Outlet out on out.id=rep.outletId where rep.cDate in :dates")
List<Object[]> getReportsByMethodAndFormulaAndTimePeriods(@Param("dates") List<LocalDate> dates);

Any ideas?

meGaMind
  • 95
  • 1
  • 7
  • I get list of Object arrays containing report Entity and areaname,But not getting report entities which have no outlet associated with them – meGaMind Aug 28 '18 at 09:44
  • Try to use [jdbc logger](https://stackoverflow.com/a/45346996/5380322) to see real sql queries and their results... – Cepr0 Aug 28 '18 at 09:50
  • please share an example, what output you are getting and what output you are expecting – Poorvi Nigotiya Aug 28 '18 at 09:51
  • JPQL joins through relations, not to random other entities. And if you think something is "not working" then at least POST the SQL that the JPA provider executed, along with your entities –  Aug 28 '18 at 10:09

1 Answers1

0

It is not SQL so join happens by entities fields. The query should be like this

@Query("Select rep,out.area.area_name from Report rep left join rep.outlet out where rep.cDate in :dates")

I assume the Report entity has a nullable field Outlet outlet.

Also in your case the out.area.area_name could fail if there is no related outlet

StanislavL
  • 56,971
  • 9
  • 68
  • 98
  • Report and Outlet entities are not connected using fields so Report entity does not have a Outlet outlet field..but has a Int outlet_id field. Can join not happen in this case? – meGaMind Aug 28 '18 at 13:27
  • Post the entities classes, please – StanislavL Aug 28 '18 at 13:52