-->
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: Need help to use query.getResultList()
PostPosted: Fri Feb 09, 2007 6:31 pm 
Newbie

Joined: Fri Feb 09, 2007 6:18 pm
Posts: 1
HI: I am using javax.persinstence.EntityManager and javax.persinstence.Query to access postgress table.

I do get a list back from the query (list size > 1)
But, I am having problem to cast my entity object to list object.

Below is my code -

Query q = getEntityManager().createQuery( query string);
java.util.list l = query.getResultList();


What I would need to do is to get the first object from the list and cast to my Entity class.

I am doing something like -

MyUser user = null;
for (Object o : l) {
user = (MyUser) o;
}

I am getting the following ClassCastException -

java.lang.ClassCastException: [Ljava.lang.Object;


Please help.
thanx


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 12, 2007 12:43 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi shahab
your query string should be looks like this
query string ="from user "

or

select user from User user

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 12, 2007 7:02 am 
Beginner
Beginner

Joined: Mon Sep 04, 2006 7:18 am
Posts: 45
When you write your own query like you have, and the list is more than 1 item, you will retrieve a Object[] array. And they again contain strings or something.

So you will need to create a Object[] and cast to that to retrieve the data.


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.