-->
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.  [ 4 posts ] 
Author Message
 Post subject: ClassCastException...
PostPosted: Wed Feb 04, 2004 8:19 am 
Regular
Regular

Joined: Mon Jan 19, 2004 10:39 pm
Posts: 84
Location: Nottingham, England
Hi,
I am having problems casting a query into a type (User). I have 2 methods, one for a known user id and one that doesn't know the user id:

1. public static User getUser (int user_id)
{
................
user = (User)session.load(test.User.class, userID);
....................
return user;
}
This works fine, but in my second method:

2.public static User getUser (String username)
{
................
user = (User)session.find("from User user where user.UserName = ?",username,Hibernate.STRING);
....................
return user;
}

This throws a class exception. How do I resolve this as I need the type of (User) returned?

many thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 8:24 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
We don't know, you haven't shown enough information to resolve this. Please read:

http://www.hibernate.org/160.html

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 8:24 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Oh, I see. You are trying to cast a List to a User. Read the documentation and check uniqueResult().

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: Christian...
PostPosted: Wed Feb 04, 2004 9:56 am 
Regular
Regular

Joined: Mon Jan 19, 2004 10:39 pm
Posts: 84
Location: Nottingham, England
works a treat. Thanks for your help ;-)


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