-->
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.  [ 5 posts ] 
Author Message
 Post subject: Select IN Problems
PostPosted: Fri Dec 07, 2007 3:42 pm 
Newbie

Joined: Tue Mar 20, 2007 5:27 pm
Posts: 12
I swear I had this working before, but now its not. I have a simple HQL of:
Code:
SELECT DISTINCT tbl  FROM AccountFee tbl WHERE tbl.account IN (:account)

I set the :account = an array of account objects. AccountFee.account is an Account object with an Account having many fees.

I get the following stack trace when I try to execute this:
Code:
org.hibernate.PropertyAccessException: could not get a field value by
reflection getter of Account.id
        at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:35)
        at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:183)
        at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3591)
        at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3307)
        at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:181)
        at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:218)
        at org.hibernate.type.EntityType.getIdentifier(EntityType.java:397)
        at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:87)
        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:2220)
        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)
        at com.speranzasystems.search.impl.SearcherImpl.search(SearcherImpl.java:58)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:301)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        at $Proxy59.search(Unknown Source)
        at ...
Caused by: java.lang.IllegalArgumentException: Can not set long field Base.id to java.util.ArrayList
        at java.lang.reflect.Field.get(Field.java:358)
        at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:32)


Base is the Parent type of Account, id does have getters/setters, I can do FROM AccountFee where account.id = 4

The sql looks fine, the import bit being:
Code:
... from AccountFee accountfee0_ where accountfee0_.account_id in (?)


Any ideas on what I'm doing wrong or if this just isn't possible? I'm using hibernate 3.2.5ga

Thanks for the help!
-Nick


Top
 Profile  
 
 Post subject: Re: Select IN Problems
PostPosted: Fri Dec 07, 2007 3:46 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
nstuart wrote:
Any ideas on what I'm doing wrong or if this just isn't possible? I'm using hibernate 3.2.5ga

Thanks for the help!
-Nick



how do you set the account array in the query?


Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 10, 2007 1:15 pm 
Newbie

Joined: Tue Mar 20, 2007 5:27 pm
Posts: 12
I use:
Code:
Query qr = ...;
query.setParameter(param, parameters.get(param));


parameters being a simple string,object map. This works for all the other types in my query (even actual object types when just search on one object not using IN).

Looking through the methods I see a setParameterList, do I need to use this instead?

(will test now actually..)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 10, 2007 1:22 pm 
Newbie

Joined: Tue Mar 20, 2007 5:27 pm
Posts: 12
Yeah, test passes now!
setParameterList was the change I needed. Didn't really think that would be causing the issue, thanks for asking the question! :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 10, 2007 1:24 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
nstuart wrote:
Looking through the methods I see a setParameterList, do I need to use this instead?

(will test now actually..)


You will need to use the list one. I don't remember if I ever did it with a String but I can think of reasons why it shouldn't work with a string.


Farzad-


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.