Skip to main content

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

Hi all,

I have the same problem.
I am using glassfish 3.0.1 (with EclipseLink 2.0.1)

using "member of" in jpql query on a collection of enum does not work.
(same exception : "You have attempted to set a value of type class
mypackage.test for parameter test with expected type of class mypackage.test
from query string ...")

Is there a workaround ?
Is it really a bug ?

if I use a Collection of String, no problem : the jpql query with "member
of" works correctly.
jpql query with single attribute Enumerated does work correctly too (no
collection : no use of member of, just = criteria)

Thanks in advance,

Maxime



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
> 
> 



-- 
View this message in context: http://old.nabble.com/Querying-%40ElementCollections-tp28308108p29591665.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top