Multiple joins did not return expected result

#1

Hello,

I have 3 entity classes:

Event
 - String title

Calendar
 - List<Event> @OneToMany

SharedCalendar extends Calendar
 - Calendar original

Now I want to retrieve all events from a specific calendar by its id like:

SELECT event
FROM Calendar c1, SharedCalendar c2
INNER JOIN c1.events AS event
INNER JOIN c2.original.events AS event
WHERE c1.id=?1 OR c2.id=?1

Unfortunately this query returns no events at all, removing the SharedCalendar from the query works as expected. How can I achieve this?

Thanks for your support.
Markus

#2

Are you sure that this query doesn't produce an error?

The event variable is defined twice. You should use a unique name for every query variable.

ObjectDB Support
#3

Hello,

So should I use the query 

SELECT event1, event2
FROM Calendar c1, SharedCalendar c2
INNER JOIN c1.events AS event1
INNER JOIN c2.original.events AS event2
WHERE c1.id=?1 OR c2.id=?1

instead? There is no error at all, just an empty result. Thats why I thought this must be working. Is there a more "elegant" way of doing this (like UNION of 2 SELECT)? There are more WHERE clauses which must be doubled if I use 2 variables.

Thanks
Markus

#4

Running two different separate queries and merging the results (e.g. into a Java set, maybe LinkedHashSet, if order is important) may be the right way.

ObjectDB Support
#5

Ok. Thank you

Reply