Stella, OpenJPA Manual section 7.7.10 XML Column Mapping documented the limited support for XML column mapping:
The path expression must be single-valued. Path expressions over XML mapped classes can only be used in the WHERE clause as an operand to a simple predicate (= <> < > >= <=). Path expressions over XML mapped fields can not be: • an input to a JPQL scalar function • an operand of BETWEEN, IS NULL, LIKE or IN predicate • used to project out subfields in the SELECT clause • used in the FROM, GROUP BY, HAVING, ORDER BY clauses Catalina On Sun, Dec 13, 2009 at 6:28 PM, Stella Lok <[email protected]>wrote: > Hi, > > I am having trouble executing a JPA named query that uses multi-valued > elements, within an XML column, as criteria. > > I have a table with the following DB2 schema: > CREATE TABLE SWD.Dummy ( > dummyId VARCHAR(32) NOT NULL, > properties XML NOT NULL > ) > DATA CAPTURE NONE; > > ALTER TABLE SWD.Dummy ADD CONSTRAINT Dummy_PK PRIMARY KEY (dummyId); > > and I used JAXB to generate the beans for marshalling & unmarshalling from > the XSD schema defined for the "properties" XML column. My XSD schema is as > follows: > > <?xml version="1.0" encoding="utf-8"?> > <xsd:schema version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> > <xsd:element name="properties" type="propertiesType" /> > <xsd:complexType name="propertiesType"> > <xsd:sequence> > <xsd:element maxOccurs="unbounded" name="property" > type="propertyType" /> > </xsd:sequence> > </xsd:complexType> > <xsd:complexType name="propertyType"> > <xsd:sequence> > <xsd:element name="keyy" type="xsd:string" /> > <xsd:element name="valuee" type="xsd:string" /> > </xsd:sequence> > </xsd:complexType> > </xsd:schema> > > In summary, the element "properties" is the root element and it contains > any number of "property" elements which in turn may contain "keyy" and > "valuee" string elements. An example of an XML compliant with the schema: > > <?xml version="1.0" encoding="UTF-16" > > ?><properties><property><keyy>abc</keyy><valuee>123</valuee></property><property><keyy>def</keyy><valuee>xyz</valuee></property></properties> > > > > I am able to use JPA to make simple queries on the Dummy entity. However, I > get an error if I try to query on the "property" element. > For example, I get an exception if I execute the following JPQL query: > SELECT d FROM Dummy d, IN (d.properties.property) p WHERE p.keyy=:keyy AND > p.valuee=:valuee > > The stack trace that I get is: > com.example.DAOException: <openjpa-2.0.0-M3-r422266:822833 nonfatal user > error> org.apache.openjpa.persistence.ArgumentException: > collection-valued-path > at com.example.DummyDAO.findDummyByProperty(DummyDAO.java:142) > at com.example.GetDummyService.invoke(GetDummyService.java:63) > ... 32 more > Caused by: > <openjpa-2.0.0-M3-r422266:822833 nonfatal user error> > org.apache.openjpa.persistence.ArgumentException: collection-valued-path > at > > org.apache.openjpa.kernel.exps.AbstractExpressionBuilder.traverseXPath(AbstractExpressionBuilder.java:269) > at > > org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getPath(JPQLExpressionBuilder.java:1921) > at > > org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.addJoin(JPQLExpressionBuilder.java:741) > at > > org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.evalFromClause(JPQLExpressionBuilder.java:680) > at > > org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.evalFromClause(JPQLExpressionBuilder.java:666) > at > > org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder.getQueryExpressions(JPQLExpressionBuilder.java:292) > at org.apache.openjpa.kernel.jpql.JPQLParser.eval(JPQLParser.java:67) > at > > org.apache.openjpa.kernel.ExpressionStoreQuery$DataStoreExecutor.<init>(ExpressionStoreQuery.java:728) > at > > org.apache.openjpa.kernel.ExpressionStoreQuery.newDataStoreExecutor(ExpressionStoreQuery.java:170) > at > org.apache.openjpa.kernel.QueryImpl.createExecutor(QueryImpl.java:742) > at > org.apache.openjpa.kernel.QueryImpl.compileForDataStore(QueryImpl.java:700) > at > org.apache.openjpa.kernel.QueryImpl.compileForExecutor(QueryImpl.java:682) > at org.apache.openjpa.kernel.QueryImpl.compile(QueryImpl.java:582) > at > > com.ibm.ws.persistence.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:104) > at > > com.ibm.ws.persistence.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:36) > at > > com.ibm.ws.jpa.management.JPATxEmInvocation.createNamedQuery(JPATxEmInvocation.java:116) > at > > com.ibm.ws.jpa.management.JPAEntityManager.createNamedQuery(JPAEntityManager.java:332) > at com.example.DummyDAO.findDummyByProperty(DummyDAO.java:137) > ... 33 more > > I've tweaked the query many times, but am unable to get it working. I > couldn't find resources online regarding this either, so I would greatly > appreciate any help on this, thank you! >
