Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Querying @ElementCollections

The error is odd, as the classes are the same.  It seems to be a  class
loader issue.  What app server are you using?  If you try the same query in
JSE, does it work?  If so please log a bug for the issue (you may also wish
to try the latest release).


Luis F. Planella Gonzalez wrote:
> 
> I'm having trouble filtering records by elements in an @ElementCollection.
> Here is my entity (only the interesting part):
> 
> @Entity
> @DiscriminatorValue(value = "GROUP")
> public class Group extends BasicGroup {
> 
>     @Basic(optional = false)
>     @Enumerated(EnumType.STRING)
>     @Column(name = "status")
>     private GroupStatus status = GroupStatus.ACTIVE;
> 
>     @ElementCollection
>     @CollectionTable(name = "groups_roles", joinColumns = @JoinColumn(name
> = "group_id"))
>     @Column(name = "role")
>     @Enumerated(EnumType.STRING)
>     private Set<Role> roles = new HashSet<Role>();
> 
> }
> 
> I thought the 'member of' operator would work, but running the query
> 'select g from Group g where g.status = :stat and :role member of
> g.roles', and passing as parameters, GroupStatus.ACTIVE and Role.ADMIN,
> and the following exception is raised:
> Caused by: java.lang.IllegalArgumentException: You have attempted to set a
> value of type class mypackage.Role for parameter role with expected type
> of class mypackage.Role from query string select g from Group g where
> g.status = :stat and :role member of g.roles.
> 	at
> org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameterInternal(EJBQueryImpl.java:1145)
> 	at
> org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameter(EJBQueryImpl.java:1020)
> 	at
> org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameter(EJBQueryImpl.java:71)
> 
> I also tried the in operator, but had the very same error on query 'select
> g from Group g, in(g.roles) r where g.status = :stat and r = :role':
> Caused by: java.lang.IllegalArgumentException: You have attempted to set a
> value of type class mypackage.Role for parameter role with expected type
> of class mypackage.Role from query string select g from Group g,
> in(g.roles) r where g.status = :stat and r = :role.
> 	at
> org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameterInternal(EJBQueryImpl.java:1145)
> 	at
> org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameter(EJBQueryImpl.java:1020)
> 	at
> org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameter(EJBQueryImpl.java:71)
> 
> 
> What is the correct way to filter rows based on a ElementCollection?
> 
> Thanks in advance,
> Luis Fernando Planella Gonzalez
> 
> 


-----
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/Querying-%40ElementCollections-tp28308108p28378170.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top