ObjectDB ObjectDB

@ElementCollection query returning extra result per element in collection



  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



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

ObjectDB Support

Yes i can work around this for now,




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

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



To post on this website please sign in.