File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Hibernate 3 / JPA: Simple Select Query returning ClassCastException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate 3 / JPA: Simple Select Query returning ClassCastException" Watch "Hibernate 3 / JPA: Simple Select Query returning ClassCastException" New topic
Author

Hibernate 3 / JPA: Simple Select Query returning ClassCastException

James Dekker
Ranch Hand

Joined: Dec 09, 2006
Posts: 215
Am using Hibernate 3 / JPA on Java 6. Am trying to fetch a simple row from the database (which is populated).

Created the following JPA Annotated Domain Object:



My hibernate.cfg.xml file:



Code snippet from calling class:



When I run the calling class, this is the exception I get:



Line 15 where this ClassCastException occurs is here:



Here are my dependencies:



What I am I possibly doing wrong? I just want to call a simple select query against a person table.

What is the most simplest way to do a select query for one row of my Person table in Hibernate / JPA?

I am using session factory instead of entity manager.

Thank you for taking the time to read this.
lavnish lalchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 79
Hi
Can you try two things
1) use query.list() instead of query.getResultList()
2) also instead of session.createQuery("SELECT p FROM Person p"); you can try session.createQuery("FROM Person");


lavnish.blogspot.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate 3 / JPA: Simple Select Query returning ClassCastException
 
Similar Threads
Hibernate query not mapped
Hibernate annotations problem
Hibernate/Mysql - previous record(s) not being persisted.
query on Hibernate
Hibernate not inserting new record on SQL Server