Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JPA query - NOT MEMBER OF exception
JPA query - NOT MEMBER OF exception [message #758003] Thu, 17 November 2011 20:19 Go to next message
Dennis Fuglsang is currently offline Dennis Fuglsang
Messages: 77
Registered: July 2009
Member
I have a very simple test case involving a single Java class, two database tables, a basic collection mapping and JPA queries. The SQL for the DB schema is shown below

CREATE TABLE Z_INSTANCES (
INSTANCE_UUID CHAR(36) NOT NULL
, NAME VARCHAR2(256)
, CONSTRAINT Z_INSTANCES_PK PRIMARY KEY (INSTANCE_UUID) using index tablespace &INDEX_TABLESPACE ENABLE) tablespace &DATA_TABLESPACE;

CREATE TABLE Z_GROUPS(
INSTANCE_UUID CHAR(36) NOT NULL
, GROUP_UUID CHAR(36) NOT NULL
, CONSTRAINT GROUPS_UK1 UNIQUE (INSTANCE_UUID,GROUP_UUID) using index tablespace &INDEX_TABLESPACE ENABLE
, CONSTRAINT Z_INSTANCES_FK1 FOREIGN KEY (INSTANCE_UUID)
REFERENCES Z_INSTANCES(INSTANCE_UUID) ON DELETE CASCADE ENABLE) tablespace &DATA_TABLESPACE;

The Java class is very simple

public class Zinstance {
private String uuid;
private String name;
private Set<String> groupUUIDs;
public Zinstance() {
this.uuid = UUID.randomUUID().toString();
this.groupUUIDs = new HashSet<String>();
}
}

The OR mapping is shown below:

<entity class="my.temp.Zinstance">
<table name="Z_INSTANCES" />
<attributes>
<id name="uuid">
<column name="INSTANCE_UUID" updatable="false" />
</id>
<basic name="name">
<column name="NAME" />
</basic>
<basic-collection name="groupUUIDs">
<value-column name="GROUP_UUID" />
<collection-table name="Z_GROUPS">
<primary-key-join-column>INSTANCE_UUID</primary-key-join-column>
</collection-table>
<private-owned />
<join-fetch>OUTER</join-fetch>
</basic-collection>
</attributes>
</entity>


I attempted the following JPA queries

SELECT a FROM Zinstance a <-Success
SELECT a FROM Zinstance a WHERE a.groupUUIDs = ?1 <-Success
SELECT a FROM Zinstance a WHERE ?1 LIKE a.groupUUIDs <-Success
SELECT a FROM Zinstance a WHERE ?1 NOT LIKE a.groupUUIDs <-Fail incorrect results
SELECT a FROM Zinstance a WHERE a.groupUUIDs IS EMPTY <-Success
SELECT a FROM Zinstance a WHERE a.groupUUIDs IS NOT EMPTY <-Success
SELECT a FROM Zinstance a WHERE ?1 MEMBER OF a.groupUUIDs <-Success
SELECT a FROM Zinstance a WHERE ?1 NOT MEMBER OF a.groupUUIDs <-Fail CCE

I am using EclipseLink 2.3.1. Is the ClassCastException for the NOT MEMBER OF a bug? Is there an alternative syntax for this type of query?

Exception [EclipseLink-6168] (Eclipse Persistence Services - 2.3.1.v20111018-r10243): org.eclipse.persistence.exceptions.QueryException
Exception Description: Query failed to prepare, unexpected error occurred: [java.lang.ClassCastException: java.lang.String cannot be cast to org.eclipse.persistence.internal.descriptors.PersistenceObject].
Internal Exception: java.lang.ClassCastException: java.lang.String cannot be cast to org.eclipse.persistence.internal.descriptors.PersistenceObject
Query: ReadAllQuery(referenceClass=Zinstance jpql="SELECT a FROM Zinstance a WHERE 'b54f6d66-07fe-4d04-97f6-acff6722236a' NOT MEMBER OF a.groupUUIDs")
at org.eclipse.persistence.exceptions.QueryException.prepareFailed(QueryException.java:1555)
at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:625)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.checkPrepare(ObjectLevelReadQuery.java:823)
at org.eclipse.persistence.queries.DatabaseQuery.prepareCall(DatabaseQuery.java:1741)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:268)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:190)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:142)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:126)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1475)
at oracle.oer.orc.persistence.temp.BasicCollectionIntegTest.query(BasicCollectionIntegTest.java:131)
Re: JPA query - NOT MEMBER OF exception [message #758045 is a reply to message #758003] Mon, 21 November 2011 19:58 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Please log a bug.

You should be able to use a join instead.

SELECT a FROM Zinstance a join a.groupUUIDs g WHERE g <> ?1

or maybe a subselect

SELECT a FROM Zinstance a WHERE not exists (Select g from a.groupUUIDs g WHERE g = ?1)


James : Wiki : Book : Blog : Twitter
Re: JPA query - NOT MEMBER OF exception [message #758047 is a reply to message #758003] Mon, 21 November 2011 19:58 Go to previous message
James is currently offline James
Messages: 272
Registered: July 2009
Senior Member
Please log a bug.

You should be able to use a join instead.

SELECT a FROM Zinstance a join a.groupUUIDs g WHERE g <> ?1

or maybe a subselect

SELECT a FROM Zinstance a WHERE not exists (Select g from a.groupUUIDs g WHERE g = ?1)

--
James : http://wiki.eclipse.org/EclipseLink : http://en.wikibooks.org/wiki/Java_Persistence : http://java-persistence-performance.blogspot.com/
Previous Topic:NullPointerException in Query.setHint with join-fetch/batch
Next Topic:Re: Must static-weaving be set in the persistence.xml file if static weaving has been performed
Goto Forum:
  


Current Time: Thu Oct 02 02:29:29 GMT 2014

Powered by FUDForum. Page generated in 0.02145 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software