Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JPQL Query List Parameter Exception
JPQL Query List Parameter Exception [message #871691] Mon, 14 May 2012 17:27 Go to next message
Chris Gieczys is currently offline Chris GieczysFriend
Messages: 2
Registered: May 2012
Junior Member
If I call findWritableAclEntry and pass it a list of valid SIDs I get the following exception:

Exception Description: Object comparisons can only use the equal() or notEqual() operators. Other comparisons must be done through query keys or direct attribute level comparisons.
Expression: [
Relation operator [ IN ]
Query Key aclSid
Base com.test.security.domain.AclEntry
Constant [
Parameter sids]]

I'm using EclipseLink 2.3.2.
This seems like it should be easy to do, but nothing I have found has been explicit in stating why I can't do this. Any suggestions?

@RooJavaBean
@NamedQueries(value = { @NamedQuery(name = AclEntry.NAME_QUERY_FIND_BY_MASK_AND_SID, query = "SELECT o FROM AclEntry AS o WHERE o.mask =:mask AND o.aclSid IN(:sids)")})
@RooEntity(table = "acl_entry")
public class AclEntry {
	private static final transient Logger logger = Logger.getLogger(AclEntry.class);
	public static final String NAME_QUERY_FIND_BY_MASK_AND_SID = "";
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id")
	private Long id;
	
	@ManyToOne(targetEntity = AclObjectIdentity.class)
	@JoinColumn(name = "acl_object_identity")
	private AclObjectIdentity aclObjectIdentity;
	
	@Column(name = "ace_order")
	private Integer aceOrder;
	
	@ManyToOne(targetEntity = AclSid.class)
	@JoinColumn(name = "sid")
	private AclSid aclSid;
	
	@Column(name = "mask")
	private Integer mask;
	
	@Column(name = "granting")
	private boolean granting;
	
	@Column(name = "audit_success")
	private boolean auditSuccess;
	
	@Column(name = "audit_failure")
	private boolean auditFailure;

 	public static List<AclEntry> findWritableAclEntryBySid(List<AclSid> sids) {
		List<AclEntry> results = new ArrayList<AclEntry>();
		
		EntityManager em = AclEntry.entityManager();
		TypedQuery<AclEntry> query = em.createNamedQuery(NAME_QUERY_FIND_BY_MASK_AND_SID, AclEntry.class);
		query.setParameter("mask", 2);
		query.setParameter("sids", sids);
		
		try {
			results.addAll(query.getResultList());
		} catch(Exception e) {
			logger.debug(e);
		}
		
		return results;
	}
}

@RooJavaBean
@RooEntity(table = "acl_sid")
public class AclSid {
    private static final transient Logger logger = Logger.getLogger(AclSid.class);

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @Column(name = "principal")
    private boolean principal;

    @Column(name = "sid")
    private String email;

	public static List<AclSid> findAclSidsByEmailEquals(String email) {
		if (email == null || email.length() == 0) throw new IllegalArgumentException("The email argument is required");
		if(logger.isTraceEnabled()) {
			logger.trace("findAclSidsByEmailEquals() -- email[" + email + "]");
		}
		
        List<AclSid> results = new ArrayList<AclSid>();
        EntityManager em = AclSid.entityManager();
        TypedQuery<AclSid> q = em.createQuery("SELECT o FROM AclSid AS o WHERE o.email = :email", AclSid.class);
        q.setParameter("email", email);
        try {
        	results.addAll(q.getResultList());
        } catch(Exception e) {
        	if(logger.isTraceEnabled()) {
        		logger.trace(e);
        	}
        }
        return results;
    }
}


Re: JPQL Query List Parameter Exception [message #871697 is a reply to message #871691] Mon, 14 May 2012 17:35 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
The error states you cannot do object comparisons using IN - the o.aclSid is a reference to the AclSid object not just its id.
Try using "o.aclSid.id in (:sids) " and then passing in a collection of AclSid ids intead of entity instances.

Best Regards,
Chris

Re: JPQL Query List Parameter Exception [message #871715 is a reply to message #871697] Mon, 14 May 2012 18:20 Go to previous messageGo to next message
Chris Gieczys is currently offline Chris GieczysFriend
Messages: 2
Registered: May 2012
Junior Member
Thanks! I figured it would automatically query and compare against the primary key. That isn't the case. I changed o.aclSid to o.aclSid.id. In addition, I had to remove the parentheses as well since that isn't appropriate for JPA 2. If you did not do this you would get

Caused by: java.lang.IllegalArgumentException: You have attempted to set a value of type class java.util.ArrayList for parameter sids with expected type of class java.lang.Long from query string SELECT o FROM AclEntry AS o WHERE o.mask =:mask AND o.aclSid.id IN (:sids).

The last thing I needed to do was pass in a list of the IDs of type java.lang.Long rather than a list of AclSid instances. If I did not do the last step it resulted in

Exception Description: The object [com.test.security.domain.AclSid@43f69b79], of class [class com.test.security.domain.AclSid], from mapping [org.eclipse.persistence.mappings.DirectToFieldMapping[id-->acl_sid.id]] with descriptor [RelationalDescriptor(com.test.security.domain.AclSid --> [DatabaseTable(acl_sid)])], could not be converted to [class java.lang.Long]
Re: JPQL Query List Parameter Exception [message #872127 is a reply to message #871715] Tue, 15 May 2012 14:05 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Note that passing a list of objects to IN should work in EclipseLink 2.4 builds.

James : Wiki : Book : Blog : Twitter
Previous Topic:Using EclipseLink in OSGi with Gemini JPA. Two questions.
Next Topic:delimited-identifiers as global option
Goto Forum:
  


Current Time: Fri Mar 29 01:08:51 GMT 2024

Powered by FUDForum. Page generated in 0.04403 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top