Skip to main content

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

Sorry if I didn't made it clear, but Role is an enum, hence, the @ElementCollection.

Luis Fernando Planella Gonzalez

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


Back to the top