File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Hibernate 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" Watch "Hibernate" New topic


Chinki Jhurani

Joined: Nov 14, 2008
Posts: 3

I have just started learning Hibernate. I am trying to reterive data using HQL but i am getting error Could not Load an entity. Query generated by HQL is correct. I am able to get value of primary key column, but whenever i try for other field, i am getting error "Could not load an entity". Please help...


Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
May be you are not sending in the key correctly. This will probably me moved to the appropriate forum.

So much trouble in the world -- Bob Marley
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63844

"Chinki JJ", please check your private messages for an important administrative matter.

Also, please take the time to choose the correct forum for your posts. This forum is for questions on JSP.

For more information, please read this.

This post has been moved to a more appropriate forum.

[Asking smart questions] [About Bear] [Books by Bear]
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Can you post your code?

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Chinki Jhurani

Joined: Nov 14, 2008
Posts: 3
I am able to reterive data if table contains only one row(No error).If table contains more than one row then its printing value of primary key column but not able to reterive other column values and getting follwing Error:

Hibernate: select insurance0_.ID as col_0_0_ from insurance insurance0_
ID: 1
Hibernate: select insurance0_.ID as ID0_, insurance0_.insurance_name as insurance2_2_0_, insurance0_.invested_amount as invested3_2_0_, insurance0_.investement_date as investem4_2_0_ from insurance insurance0_ where insurance0_.ID=?
could not load an entity: [test.hibernate.Insurance#1]

Resource Mapping file

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"

<class name="test.hibernate.Insurance" table="insurance">
<id name="lngInsuranceId" column="ID" type="long">
<generator class="increment"/>

<property name="insuranceName">
<column name="insurance_name" />
<property name="investementAmount">
<column name="invested_amount" />

<property name="investementDate">
<column name="investement_date" />


Java File

public class SelectHQLExample {

public static void main(String[] args) {
Session session = null;

// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();

//Using from Clause
String SQL_QUERY =" from Insurance as insurance";
Query query = session.createQuery(SQL_QUERY);
for(Iterator it=query.iterate();it.hasNext() {
Insurance insurance=(Insurance);

System.out.println("ID: " + insurance.getLngInsuranceId());

System.out.println("First Name: " + insurance.getInsuranceName());

System.out.println("Amount " + insurance.getInvestementAmount());

System.out.println("Date:: " + insurance.getInvestementDate());


}catch(Exception e){

Chinki Jhurani

Joined: Nov 14, 2008
Posts: 3
Please help.... i'm waiting for reply..
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63844

"Chinki JJ", My request that you change your display name to adhere to JavaRanch standards was not a suggestion. Valid display names are mandatory for participation on the Ranch. Please change your display name as instructed prior to your next post.

Be aware that accounts with invalid display names are disabled.

JavaRanch Sheriff
I agree. Here's the link:
subject: Hibernate
It's not a secret anymore!