[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] Problem with attributes of a ElementCollection in Query
|
This seems to be an issue with JPQL and ElementCollections. Please log a bug
for this issue.
As a workaround using a Criteria Query or an EclipseLink Expression query
should work. Or you can change the ElementCollection to a OneToMany and an
Entity.
mqn wrote:
>
> I try to use eclipseLink instead of hibernate and have problems with a
> query that uses attributes of an elementcollection (The same query works
> with hibernate). Escort is an Entity and Location is @Embeddable
>
> The query:
>
>
>
> @Entity(name="Escort")
> @Table(name="escort")
> @Access(AccessType.FIELD)
> @NamedQueries({
> @NamedQuery(name=EscortImpl.FIND_ESCORT_BY_LOCATION,
> query="select distinct(e) from Escort e left outer join e.locations l
> where l.longitude >= :minLongitude
> and l.longitude <= :maxLongitude
> and l.latitude >= :minLatitude
> and l.latitude <= :maxLatitude
> and l.validFromDate <= :minDate and l.expirationDate > :maxDate
> })
>
> public class EscortImpl implements Escort {
>
> ...
>
> @ElementCollection(targetClass=LocationImpl.class)
> @CollectionTable(name="escort_location",
> joinColumns={@JoinColumn(name="escort_id")})
> private Set<Location> locations = new HashSet<Location>();
>
> ...
>
> }
>
> @Embeddable
> public class LocationImpl implements Location {
> ...
> }
>
>
> The stacktrace is
>
>
> org.springframework.transaction.CannotCreateTransactionException: Could
> not open JPA EntityManager for transaction; nested exception is
> javax.persistence.PersistenceException: Exception [EclipseLink-8030]
> (Eclipse Persistence Services - 2.0.0.v20091127-r5931):
> org.eclipse.persistence.exceptions.JPQLException
> Exception Description: Error compiling the query [findEscortByLocation:
> select distinct(e) from Escort e left outer join e.locations l where
> l.longitude >= :minLongitude and l.longitude <= :maxLongitude and
> l.latitude >= :minLatitude and l.latitude <= :maxLatitude and
> l.validFromDate <= :minDate and l.expirationDate > :maxDate], line 1,
> column 74: unknown state or association field [longitude] of class
> [de.mq.xstore.dom.LocationImpl].
> at
> org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:382)
> at
> org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
> at
> org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:336)
> at
> org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:102)
> at
> org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
> at
> org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
> at $Proxy19.createOrUpdateEscort(Unknown Source)
> at
> de.mq.xstore.itest.TestEscortService.testCreateEscort(TestEscortService.java:63)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:623)
> at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
> at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
> at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
> at
> org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
> at
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
> at
> org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
> at
> org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
> at
> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
> at
> org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
> at
> org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
> at
> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
> at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
> Caused by: javax.persistence.PersistenceException: Exception
> [EclipseLink-8030] (Eclipse Persistence Services - 2.0.0.v20091127-r5931):
> org.eclipse.persistence.exceptions.JPQLException
> Exception Description: Error compiling the query [findEscortByLocation:
> select distinct(e) from Escort e left outer join e.locations l where
> l.longitude >= :minLongitude and l.longitude <= :maxLongitude and
> l.latitude >= :minLatitude and l.latitude <= :maxLatitude and
> l.validFromDate <= :minDate and l.expirationDate > :maxDate], line 1,
> column 74: unknown state or association field [longitude] of class
> [de.mq.xstore.dom.LocationImpl].
> at
> org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:392)
> at
> org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:151)
> at
> org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:207)
> at
> org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:195)
> at
> org.springframework.orm.jpa.JpaTransactionManager.createEntityManagerForTransaction(JpaTransactionManager.java:400)
> at
> org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:321)
> ... 36 more
> Caused by: Exception [EclipseLink-8030] (Eclipse Persistence Services -
> 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.JPQLException
> Exception Description: Error compiling the query [findEscortByLocation:
> select distinct(e) from Escort e left outer join e.locations l where
> l.longitude >= :minLongitude and l.longitude <= :maxLongitude and
> l.latitude >= :minLatitude and l.latitude <= :maxLatitude and
> l.validFromDate <= :minDate and l.expirationDate > :maxDate], line 1,
> column 74: unknown state or association field [longitude] of class
> [de.mq.xstore.dom.LocationImpl].
> at
> org.eclipse.persistence.exceptions.JPQLException.unknownAttribute(JPQLException.java:457)
> at
> org.eclipse.persistence.internal.jpa.parsing.DotNode.validate(DotNode.java:78)
> at
> org.eclipse.persistence.internal.jpa.parsing.Node.validate(Node.java:91)
> at
> org.eclipse.persistence.internal.jpa.parsing.BinaryOperatorNode.validate(BinaryOperatorNode.java:34)
> at
> org.eclipse.persistence.internal.jpa.parsing.GreaterThanEqualToNode.validate(GreaterThanEqualToNode.java:40)
> at
> org.eclipse.persistence.internal.jpa.parsing.Node.validate(Node.java:91)
> at
> org.eclipse.persistence.internal.jpa.parsing.LogicalOperatorNode.validate(LogicalOperatorNode.java:39)
> at
> org.eclipse.persistence.internal.jpa.parsing.Node.validate(Node.java:91)
> at
> org.eclipse.persistence.internal.jpa.parsing.LogicalOperatorNode.validate(LogicalOperatorNode.java:39)
> at
> org.eclipse.persistence.internal.jpa.parsing.Node.validate(Node.java:91)
> at
> org.eclipse.persistence.internal.jpa.parsing.LogicalOperatorNode.validate(LogicalOperatorNode.java:39)
> at
> org.eclipse.persistence.internal.jpa.parsing.Node.validate(Node.java:91)
> at
> org.eclipse.persistence.internal.jpa.parsing.LogicalOperatorNode.validate(LogicalOperatorNode.java:39)
> at
> org.eclipse.persistence.internal.jpa.parsing.Node.validate(Node.java:91)
> at
> org.eclipse.persistence.internal.jpa.parsing.LogicalOperatorNode.validate(LogicalOperatorNode.java:39)
> at
> org.eclipse.persistence.internal.jpa.parsing.WhereNode.validate(WhereNode.java:34)
> at
> org.eclipse.persistence.internal.jpa.parsing.ParseTree.validate(ParseTree.java:211)
> at
> org.eclipse.persistence.internal.jpa.parsing.ParseTree.validate(ParseTree.java:187)
> at
> org.eclipse.persistence.internal.jpa.parsing.ParseTree.validate(ParseTree.java:177)
> at
> org.eclipse.persistence.internal.jpa.parsing.JPQLParseTree.populateReadQueryInternal(JPQLParseTree.java:110)
> at
> org.eclipse.persistence.internal.jpa.parsing.JPQLParseTree.populateQuery(JPQLParseTree.java:84)
> at
> org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:202)
> at
> org.eclipse.persistence.internal.jpa.JPAQuery.processJPQLQuery(JPAQuery.java:106)
> at
> org.eclipse.persistence.internal.jpa.JPAQuery.prepare(JPAQuery.java:90)
> at
> org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:464)
> at
> org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:430)
> at
> org.eclipse.persistence.internal.sessions.AbstractSession.processJPAQueries(AbstractSession.java:1747)
> at
> org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:409)
> at
> org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:671)
> at
> org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:633)
> at
> org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:230)
> at
> org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:368)
> ... 41 more
>
>
> I interprete it, that there is a prblem, because longitude and latitude
> are not initialized. Using hibernate this kind of problems can be solve
> (somethimgs), to use left outer join fetch, but in EclipseLink there seams
> to be no way to give an alias after the fetch . For example:
>
> left outer join fetch e.locations l
>
> Fetch and alias can not be used together ???
>
> To use Eager fetching for the ElementCollection didn't solve the problem.
>
>
> I think there is only one solution: Change LoctionImpl to an Entity and
> use a normal Collection and a subquery. But if there is no other solution,
> I think ElementCollections are not very usefull in general ...
>
> Did somebody have an idea ?
>
>
>
>
>
-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland
http://www.eclipse.org/eclipselink/
EclipseLink , http://www.oracle.com/technology/products/ias/toplink/
TopLink
Wiki: http://wiki.eclipse.org/EclipseLink EclipseLink ,
http://wiki.oracle.com/page/TopLink TopLink
Forums: http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink ,
http://www.nabble.com/EclipseLink-f26430.html EclipseLink
Book: http://en.wikibooks.org/wiki/Java_Persistence Java Persistence
--
View this message in context: http://old.nabble.com/Problem-with-attributes-of-a-ElementCollection-in-Query-tp28574649p28599692.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.