-->
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.  [ 6 posts ] 
Author Message
 Post subject: Cast problem
PostPosted: Fri Jul 16, 2004 1:33 pm 
Newbie

Joined: Fri Jul 16, 2004 10:55 am
Posts: 3
I can use the methods Session.save() and Session.load() without problems, when i save, the table is updated, when use the load method i can convert the objetc in this way (MyClass) Session.load (MyClass, objid) and everything is allright.
When i use query.list() to retrive all records, this list is created with the correct size (equal to the numbers of records), but if i try of cast the objects of my list, the next error appear : "CastClassException".

_________________
Santiago Iacobelli
santiago@cyneric.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 16, 2004 2:39 pm 
Beginner
Beginner

Joined: Tue Jun 29, 2004 3:44 pm
Posts: 43
Can you post the code where you make the query and where you cast an item in the list?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 16, 2004 4:18 pm 
Newbie

Joined: Fri Jul 16, 2004 10:55 am
Posts: 3
scrotch wrote:
Can you post the code where you make the query and where you cast an item in the list?


Thanks for you help, but the problem was that i try to use the next sintax:
"Query query = session.createQuery("select p.id, p.descripcion from prueba p"); "
and to retrieve the list
"query.list()"

In the reference manual of hibernate i find a diferent sintax, then change my code to:

Prueba fritz =new Prueba();
Query query = session.createSQLQuery("select {fritz.*} from prueba {fritz}", "fritz", Prueba.class);

to retrieve list: rows = query.list();

in this way i don't need cast the list elements!!

Thanks for your answer!!!!!!

_________________
Santiago Iacobelli
santiago@cyneric.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 16, 2004 5:34 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
the queries are different
the first return a list of object[]

the second returns a list of object

just change the first from
Code:
Query query = session.createQuery("select p.id, p.descripcion from prueba p"); "

to
Code:
Query query = session.createQuery("from prueba p"); "


and read the doc
http://www.hibernate.org/hib_docs/refer ... hql-select

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 20, 2004 9:36 am 
Newbie

Joined: Fri Jul 16, 2004 10:55 am
Posts: 3
anthony wrote:
the queries are different
the first return a list of object[]

the second returns a list of object

just change the first from
Code:
Query query = session.createQuery("select p.id, p.descripcion from prueba p"); "

to
Code:
Query query = session.createQuery("from prueba p"); "


and read the doc
http://www.hibernate.org/hib_docs/refer ... hql-select


Anthony:
When i create the query with this
Code:
Query query = session.createQuery("from prueba p");
, i retrieve a RuntimeException with this message "in expected"
Do you know the cause of this???
Thanks for you time!!!!

_________________
Santiago Iacobelli
santiago@cyneric.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 20, 2004 9:38 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
When asking questions, give at least:
the Hibernate version
your mapping documents
the Java code between sessionFactory.openSession() and session.close()
the full stack trace of any exception that occurs
the name and version of the database you are using
a debug level Hibernate log excerpt is also appreciated

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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