• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate 3 / JPA: Simple Select Query returning ClassCastException

 
Ranch Hand
Posts: 231
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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");

 
I don't like that guy. The tiny ad agrees with me.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic