-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: ArrayList of Composite Keys in HQL IN clause.
PostPosted: Wed Oct 14, 2009 11:12 pm 
Newbie

Joined: Mon Sep 26, 2005 1:01 pm
Posts: 5
I have a simple HQL Named Query

SELECT p FROM Photo p WHERE p.pk IN (:photoPks)

I set the Parameter with a List<PhotoPk> objects, and it writes the correct query format with the WHERE clause looking like

WHERE (event_id, scan_num) IN ( ( ?, ?) , (?, ?))....

but when it tries to assign the parameter values it is trying to set an in for eventId to the entire ArrayList and throws an exception.

Code:
Caused by: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of com.pictage.core.client.event.domain.PhotoPk.eventId
   at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:35)
   at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValue(AbstractComponentTuplizer.java:64)
   at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValues(AbstractComponentTuplizer.java:70)
   at org.hibernate.tuple.component.PojoComponentTuplizer.getPropertyValues(PojoComponentTuplizer.java:86)
   at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:353)
   at org.hibernate.type.ComponentType.nullSafeGetValues(ComponentType.java:326)
   at org.hibernate.type.ComponentType.nullSafeSet(ComponentType.java:281)
   at org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:38)
   at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:491)
   at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1563)
   at org.hibernate.loader.Loader.doQuery(Loader.java:673)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
   at org.hibernate.loader.Loader.doList(Loader.java:2213)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
   at org.hibernate.loader.Loader.list(Loader.java:2099)
   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
   at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
   at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
....
Caused by: java.lang.IllegalArgumentException: Can not set int field com.company.core.client.event.domain.PhotoPk.eventId to java.util.ArrayList
   at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)
   at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)
   at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37)
   at sun.reflect.UnsafeIntegerFieldAccessorImpl.getInt(UnsafeIntegerFieldAccessorImpl.java:38)
   at sun.reflect.UnsafeIntegerFieldAccessorImpl.get(UnsafeIntegerFieldAccessorImpl.java:18)
   at java.lang.reflect.Field.get(Field.java:358)
   at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:32)
   ... 68 more


Here is the composite object

Code:
@Embeddable
public class PhotoPk

    private int eventId;
    private int scanNum;


I must be doing something stupid here, as usual, as all the Google searching and looking at the Hibernate docs and FAQs and searching the forum I didn't have any luck.

Thanks

Mark


Top
 Profile  
 
 Post subject: Re: ArrayList of Composite Keys in HQL IN clause.
PostPosted: Thu Oct 15, 2009 3:15 pm 
Newbie

Joined: Mon Sep 26, 2005 1:01 pm
Posts: 5
I told you it was something stupid on my part.

I was calling setParameter() instead of setParameterList().

Mark


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.