-->
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.  [ 3 posts ] 
Author Message
 Post subject: hibernate: query using list
PostPosted: Tue Jun 18, 2013 7:30 am 
Newbie

Joined: Tue Jun 18, 2013 6:34 am
Posts: 2
Hi ,
I am new to Hibernate. i have a problem while iterating an ArrayList . I get this ArrayList from query using list.
My Code is here,

Code:
List<Long> userList = Arrays.asList(3L, 4L);

Query entityListQuery = session.createSQLQuery("select id from UserEntity where id in (:ids)");
entityListQuery.setParameterList("ids", userList);


ArrayList<UserEntity> UserEntity =  null;
UserEntity = (ArrayList<UserEntity>) entityListQuery.list();


I have fetch a list (UserEntity) of values from this query.

While iterating the list ,
Code:
for(UserEntity entity :UserEntity){
UserDAO.getUser(entity.getId(), false);   
}


i am getting an error like this
java.math.BigInteger cannot be cast to UserEntity.
how can i solve this. please help me


Top
 Profile  
 
 Post subject: Re: hibernate: query using list
PostPosted: Wed Jun 19, 2013 3:42 am 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
instead of
Code:
session.createSQLQuery("select id from UserEntity where id in (:ids)");


change to
Code:
session.createSQLQuery("from UserEntity where id in (:ids)");


Top
 Profile  
 
 Post subject: Re: hibernate: query using list
PostPosted: Wed Jun 19, 2013 5:10 am 
Newbie

Joined: Tue Jun 18, 2013 6:34 am
Posts: 2
Thanks a lot SIau_Tie. Its working fine. i understood the problem.


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