-1

I am new in Hibernate This is my JPA/Hibernate query with multiple left join so, I want know How write query in JPA. Parameters is optional may change one/two/three parameter. I want order may be null or Animal,dosage,cassete_code also add filter is Map elements.

e.g. where s.study_fk=2 order by dosage,animal and dosage="High"/animal=104/organ="liver".

But this parameters are optinal...

SELECT d.level, s.slide_pk from slideimage s
LEFT JOIN studyanimal a ON s.animal_fk=a.animal_pk
LEFT JOIN study_dosage sd ON a.study_dos_fk=sd.study_dos_pk
LEFT JOIN dosage d ON sd.dosage_fk=d.dosage_pk
where s.study_fk=2 order by d.level;

I am stuck here please help me guys. (Sorry for bad english.)

SUNIL
  • 9
  • 2

1 Answers1

0

If you've written your entity correctly (@OneToMany relationships), you simply have to select the top level entity itself.

E.g.

SELECT s FROM SlideImage s
LEFT JOIN s.studyAnimal a
LEFT JOIN a.studyDosage sd
LEFT JOIN sd.dosage d
WHERE s.study = ?1

Will result in a collection of SlideImage entites with their nested attributes populated.

Andy N
  • 1,238
  • 1
  • 12
  • 30