> .raw("mMarkedForDeletion is ?", false)
We're using HSQLDB version 2.4.1
> - setDistinct(false)
We're using ebean 12.7.2.
I'll add an extract of the node to explain the case.
class Node {
...
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name = "node_id", referencedColumnName = "node_id", insertable = false, updatable = false)
private List<ShareEbean> mShares;
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name = "node_id", referencedColumnName = "node_id", insertable = false, updatable = false)
private List<NodeCustomAttributesEbean> mCustomAttributes;
...
}
Both ShareEbean and NodeCustomAttributesEbean have an embeddedId composed of two fields.
I'll paste a case that we were trying to solve before having to switch to solutions we are using to circumvent the problem
this.db.find(Node.class)
.where()
.raw("mMarkedForDeletion is ?", false)
.or()
.eq("mOwnerId", userId)
.eq("mShares.mComposedPrimaryKey.mTargetUserId", userId)
.endOr();
db is an instance of the Database class.
We then save the query in the class since the other conditions are optional and if necessary we append
this.query
.filterMany("mCustomAttributes")
.eq("mCustomAttributes.mFlag", true)
.eq("mCustomAttributes.mCompositeId.mUserId", userId)
Which is the filtermany condition causing the aforementioned problem
We then close and start the query with:
Even without ordering the problem does not change.
But looking at the db we see the sent query always starts with "select distinct" , trying to examine the code we saw that distinct is added if setDistinct is true OR ebean evaluates the query needed that, and it seems in case of a join it always adds that, being an OR condition setDistinct(false) cannot override that calculation.
( ebean-core-12.7.2.jar!/io/ebeaninternal/server/query/CQueryBuilder.class row 594
this.distinct = query.isDistinct() || select.isSqlDistinct();
Shouldn't this condition be and AND instead of an OR ? )
On other note we are having now bit of a problem while unit testing ebean query. We have usually no problem mocking finds like:
when(mEbeanServerMock.find(Node.class)
.where()
.idEq(mNodeId)
.findOneOrEmpty()
).thenReturn(Optional.of(node));
but when trying to mock calls with ordering it give exception since :
when(mEbeanServerMock.find(Node.class)
.where()
.idEq(mNodeId)
.order.asc(Drive.Db.Node.NAME)
.findOneOrEmpty()
).thenReturn(Optional.of(node));
order ( or orderBy) returns null ( even when mocking ebeanServer with deepstubs) since orderBy is final and cannot be mocked thus preventing us for being able to mock and test server find with ordering.