-->
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.  [ 1 post ] 
Author Message
 Post subject: I'm stuck! Exception caused by HQL 'in()' query
PostPosted: Fri Apr 16, 2010 5:16 am 
Beginner
Beginner

Joined: Wed Dec 10, 2008 5:59 am
Posts: 47
Hi,

Every time i execute the below code, i get an IllegalArgumentException.

Code:
Query q1 = currentSession.createQuery("from Track t");
q1.setMaxResults(100);
List<Track> tracks = (List<Track>) q1.list();

Query q2 = currentSession.createQuery("from Track t left join fetch t.files where t in (:tracks)");
q2.setParameter("tracks", tracks);
q2.list();


Track is a subclass of BaseEntity, where the getId() and setId() methods are found.The error message i
keep getting is:

Code:
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.tracker.robot.db.entities.BaseEntity.id
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:195)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:199)
[...]
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)


If i replace the second query with the below, everything works fine. However, that issues a subquery - which takes longer.

Code:
Query q2 = currentSession.createQuery("from Track t left join fetch t.files where t in (select Track t1 where t1.flag = 2)");


Does anyone have an idea about why i keep getting this error. I can't see why Hibernate is unable to understand the
second query as
Code:
SELECT [fields] FROM track WHERE where track.id in([ids of all tracks])
?

I'd love to hear any ideas or suggestions as to how i might be able to solve this issue!


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

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.