Query which Uses isNull() after a Many-To-Many Relationship Fails (Doc ID 1065411.1)

Last updated on AUGUST 16, 2016

Applies to:

Oracle TopLink - Version: 11.1.1.0.1 and later   [Release: Oracle11g and later ]
Information in this document applies to any platform.

Symptoms

Using the following query:
ReadAllQuery query = new ReadAllQuery();
Expression rootExpression = query.getExpressionBuilder();

query.setReferenceClass(CityBO.class);
query.setSelectionCriteria(rootExpression.anyOfAllowingNone("street").isNull());

where the CityBO's street attribute is mapped as:
@javax.persistence.ManyToMany(cascade = { javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.REFRESH }, fetch = javax.persistence.FetchType.LAZY)
@javax.persistence.JoinTable(name = "CITY_STREET_STREET", joinColumns = @javax.persistence.JoinColumn(name = "CITY"), inverseJoinColumns = @javax.persistence.JoinColumn(name = "STREET"))
private java.util.Set street = new java.util.HashSet();

 fails with:

[junit] [EL Warning]: 2010-01-22 14:11:14.593--UnitOfWork(19256862)--Thread(Thread[main,5,main])--Exception [EclipseLink-6076] (Eclipse Persistence Services - 1.1.1.v20090430-r4097): org.eclipse.persistence.exceptions.QueryException
[junit] Exception Description: Object comparisons can only be used with OneToOneMappings. Other mapping comparisons must be done through query keys or direct attribute level comparisons.
[junit] Mapping: [org.eclipse.persistence.mappings.ManyToManyMapping[street]]
[junit] Expression: [
[junit] Query Key street
[junit] Base testcase.CityBO]
[junit] Query: ReadAllQuery(referenceClass=CityBO )
[junit] Exception Description: Object comparisons can only be used with OneToOneMappings. Other mapping comparisons must be done through query keys or direct attribute level comparisons.
[junit] Mapping: [org.eclipse.persistence.mappings.ManyToManyMapping[street]]
[junit] Expression: [
[junit] Query Key street
[junit] Base testcase.CityBO]
[junit] Query: ReadAllQuery(referenceClass=CityBO ))
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 1,313 sec
[junit] Test testcase.TestEclipseLink FAILED

Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms