435 words

@ElementCollection query returning extra result per element in collection

#1
2011-07-21 15:09

Hi,

  I'm having a hard time narrowing down an issue that only became apparent with in the UI. The issue is that, I'm getting repeated results of the owning entity of an '@ElementCollection'. The entity returned is repeated for every element in the collection. Switching back to EclipseLink (with the same code) yields the correct answer (that is, no duplication). I can't quite narrow down the condition under which it happens, but I have supplied a test below that shows what I'm trying to figure out. I'm not saying that there is a bug - I'm just confused about the outcome. Could be that I'm being confused about JPA2 criteria again. 

Here is the example output, with a new DB (empty db):

 

testFindByLikeLowerWildcardWithoutBranchWithOr: SELECT $1 FROM Company $1 WHERE ((LOWER($1.name) LIKE :p1) AND (($1.conditionOne=:p2)))
Got: 1 results - correct

 


testFindByLikeLowerWildcardWithBranchWithOr: SELECT $1 FROM Company $1 WHERE ((LOWER($1.name) LIKE :p1) AND ((($1.branches.branch=:p2) OR ($1.conditionOne=:p3))))
Only expected one result, but got: 2

 

Again, this is only an engineered test to show the problem on the real application.  As can be seen from the output, only an extra 'or' condition is given - yet even though the binded value evaluates to a 'false' condition, and extra entity is returned. 

Any help is appreciated!

 

ObjectDB Version: 2.2.8_06

 

Willks
Willks's picture
Joined on 2011-04-04
User Post #30
#2
2011-07-21 23:46

It seems as a bug in an ObjectDB query optimization - use an explicit DISTINCT as a workaround until a fix is released:

query.select(companyRoot).distinct(true);
ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #467
#3
2011-07-22 01:11

Yes i can work around this for now,

 

thanks.

Willks
Willks's picture
Joined on 2011-04-04
User Post #31
#4
2011-07-24 01:24

After rethinking - I am not sure that this is a bug.

Your query defines an implicit JOIN (on branches), so selection of (company,branch) should return the same company with different branches that match the filter. Similarly, selection of only companies may return duplicate objects if DISTINCT is not specified.

Could you please check this query with EclipseLink:

  • When the selection includes also a branch.
  • When Branch is defined as entity rather than as embeddable.

It may help understanding the difference between EclipseLink and ObjectDB in this case.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #472
#5
2011-07-24 01:36

My apologies.

  My test is absolutely flawed - I lost a lot in the 'translation' of trying to replicate what was happening in my app. After re-writing the test for odb/eclipselink (same test, different EMF) the exact same behaviour is observed. I still have a difference in behaviour in my app, but I can't say what this is for now. The issue in my app is that the 'count' of the records is different to the actual retrieval (both using the same queries). THe distinct condition is easy to add to my entities, but not so easy to add with the 'count' while re-using the same predicates.

 

This is indeed, not a bug

Willks
Willks's picture
Joined on 2011-04-04
User Post #32

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