Run complex SQL Query with spring boot repositories

Viewed 300

i have a little complex scenario using spring data and jpa currently.

My data structure is like: enter image description here

And i like to create a filter: give me all events which belongs to a list of structures, within a given period and is assigned to a list of categories.

I was able to create a sample SQL statement:

select * from event e inner join period p on e.period_id=p.id
inner join category_item_ids ci on e.id=ci.item_ids
inner join category c on ci.category_id=c.id
inner join event_assignment_structure_ids es on es.event_assignment_id=e.id
where p.start between '2020-05-01 12:00:00.000000' and '2020-11-14 12:00:00.000000' and
      c.id in (1) and
      es.structure_ids in (1,2)

But my objects are currently not wired together by all the JPA annotations. e.g. the "Same ID" is something i did by convention to make the parts a little more independend.

So using the JPA way is currently no option i guess due to the missing relations. Introducing them will be also quite a lot of work.

So i was wondering if there is a possiblity to run the sql query directly (i could use native query, but thats also no option, cause the filter values are not always given, so i need 13 native queries)

I used enityManager and query Builder in the past, but thats also no option due to the missing jpa relations.

Any ideas are much welcome :-) Regards Oliver

0 Answers
Related