194 words

Multiple joins did not return expected result

#1
2017-10-27 07:49

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

doppelrittberger
doppelrittberger's picture
Joined on 2016-01-13
User Post #31
#2
2017-10-27 13:00

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #2,867
#3
2017-10-27 13:13

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

doppelrittberger
doppelrittberger's picture
Joined on 2016-01-13
User Post #33
#4
2017-10-29 10:40

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #2,869
#5
2017-10-29 18:47

Ok. Thank you

doppelrittberger
doppelrittberger's picture
Joined on 2016-01-13
User Post #34

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Attachments:
Maximum file size: 32 MB
Cancel