Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Problem with @OneToMany from an @Embeddable
icon8.gif  Problem with @OneToMany from an @Embeddable [message #741374] Wed, 19 October 2011 09:23 Go to next message
dimo.velev is currently offline dimo.velev
Messages: 13
Registered: August 2011
Junior Member
Hi everyone,

I am using EclipseLink 2.3.0 and stumbled upon the following problem. I have the classes as shown in the attachment class diagram: index.php/fa/4422/0/

When I run the JPQL query
select t from Train t, WagonPlacement p where p member of t.composition.wagons and p.wagon.interesting = true
I get an error from EclipseLink saying that Quote:
error invalid collection member declaration [wagons], expected collection valued association field

Do you have any ideas how to fix my query OR workaround the bug (if it is a bug).
According to the docs EclipseLink JPA 2 supports all association kinds from embeddables and reverse links should be directed to the parent of the embeddable (as I have done between WagonPlacement and Train).

Cheers,
Dimo
Re: Problem with @OneToMany from an @Embeddable [message #748379 is a reply to message #741374] Mon, 24 October 2011 13:10 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Could be an issue with "member of"

try,
Select t from Train t join t.composition.wagons p where p.wagon.interesting = true

Also ensure you have the latest release, older releases < 1.2 may not have supports traversals from embeddables in JPQL.


James : Wiki : Book : Blog : Twitter
Re: Problem with @OneToMany from an @Embeddable [message #756885 is a reply to message #748379] Tue, 15 November 2011 07:40 Go to previous messageGo to next message
dimo.velev is currently offline dimo.velev
Messages: 13
Registered: August 2011
Junior Member
Hi James,
I tried that but I get an exception:

Exception [EclipseLink-6070] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.QueryException
Exception Description: Invalid use of a query key [org.eclipse.persistence.mappings.OneToManyMapping[wagons]] representing a "to-many" relationship in an expression.  Use anyOf() rather than get().
	at org.eclipse.persistence.exceptions.QueryException.invalidUseOfToManyQueryKeyInExpression(QueryException.java:752)
	at org.eclipse.persistence.internal.expressions.QueryKeyExpression.validateNode(QueryKeyExpression.java:887)
	at org.eclipse.persistence.expressions.Expression.normalize(Expression.java:2978)
	at org.eclipse.persistence.internal.expressions.DataExpression.normalize(DataExpression.java:342)
	at org.eclipse.persistence.internal.expressions.QueryKeyExpression.normalize(QueryKeyExpression.java:612)
	at org.eclipse.persistence.internal.expressions.QueryKeyExpression.normalize(QueryKeyExpression.java:599)
	at org.eclipse.persistence.internal.expressions.SQLSelectStatement.normalize(SQLSelectStatement.java:1311)
	at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.buildNormalSelectStatement(ExpressionQueryMechanism.java:516)
	at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.prepareSelectAllRows(ExpressionQueryMechanism.java:1602)
	at org.eclipse.persistence.queries.ReadAllQuery.prepareSelectAllRows(ReadAllQuery.java:705)
	at org.eclipse.persistence.queries.ReadAllQuery.prepare(ReadAllQuery.java:642)
	at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:598)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.checkPrepare(ObjectLevelReadQuery.java:839)
	at org.eclipse.persistence.queries.DatabaseQuery.prepareCall(DatabaseQuery.java:1719)
	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 org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1497)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

Any other ideas how I could work around that in EclipseLink? I am using the latest version available.
Best regards,
Dimo
Re: Problem with @OneToMany from an @Embeddable [message #756886 is a reply to message #748379] Tue, 15 November 2011 07:40 Go to previous messageGo to next message
dimo.velev is currently offline dimo.velev
Messages: 13
Registered: August 2011
Junior Member
Hi James,
I tried that but I get an exception:

Exception [EclipseLink-6070] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.QueryException
Exception Description: Invalid use of a query key [org.eclipse.persistence.mappings.OneToManyMapping[wagons]] representing a "to-many" relationship in an expression. Use anyOf() rather than get().
at org.eclipse.persistence.exceptions.QueryException.invalidUseOfToManyQueryKeyInExpression(QueryException.java:752)
at org.eclipse.persistence.internal.expressions.QueryKeyExpression.validateNode(QueryKeyExpression.java:887)
at org.eclipse.persistence.expressions.Expression.normalize(Expression.java:2978)
at org.eclipse.persistence.internal.expressions.DataExpression.normalize(DataExpression.java:342)
at org.eclipse.persistence.internal.expressions.QueryKeyExpression.normalize(QueryKeyExpression.java:612)
at org.eclipse.persistence.internal.expressions.QueryKeyExpression.normalize(QueryKeyExpression.java:599)
at org.eclipse.persistence.internal.expressions.SQLSelectStatement.normalize(SQLSelectStatement.java:1311)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.buildNormalSelectStatement(ExpressionQueryMechanism.java:516)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.prepareSelectAllRows(ExpressionQueryMechanism.java:1602)
at org.eclipse.persistence.queries.ReadAllQuery.prepareSelectAllRows(ReadAllQuery.java:705)
at org.eclipse.persistence.queries.ReadAllQuery.prepare(ReadAllQuery.java:642)
at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:598)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.checkPrepare(ObjectLevelReadQuery.java:839)
at org.eclipse.persistence.queries.DatabaseQuery.prepareCall(DatabaseQuery.java:1719)
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 org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1497)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

Any other ideas how I could work around that in EclipseLink? I am using the latest version available.
Best regards,
Dimo
Re: Problem with @OneToMany from an @Embeddable [message #757804 is a reply to message #756886] Mon, 21 November 2011 13:16 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

What JPQL did you try exactly? Did you use a join?

James : Wiki : Book : Blog : Twitter
Re: Problem with @OneToMany from an @Embeddable [message #758010 is a reply to message #756886] Mon, 21 November 2011 13:16 Go to previous message
James is currently offline James
Messages: 272
Registered: July 2009
Senior Member
What JPQL did you try exactly? Did you use a join?
--
James : http://wiki.eclipse.org/EclipseLink : http://en.wikibooks.org/wiki/Java_Persistence : http://java-persistence-performance.blogspot.com/
Previous Topic:Select from partition ?
Next Topic:PerformanceMonitor in Standalone or OSGI environment?
Goto Forum:
  


Current Time: Thu Apr 17 08:49:14 EDT 2014

Powered by FUDForum. Page generated in 0.02758 seconds