my dog learned polymorphism*
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
Author

Hibernate

Chinki Jhurani
Greenhorn

Joined: Nov 14, 2008
Posts: 3
Hi,

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...

Regard's

Chinki
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.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

"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] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Can you post your code?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Chinki Jhurani
Greenhorn

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"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>


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

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

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


</hibernate-mapping>



Java File

public class SelectHQLExample {

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

try{
// 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)it.next();
System.out.println("Before");

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());


}

session.close();
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
}

}
}
Chinki Jhurani
Greenhorn

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

Joined: Jan 10, 2002
Posts: 60780
    
  65

"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.

bear
JavaRanch Sheriff
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate
 
Similar Threads
jboss jpa persistence
Best Way to handle the table update(Concurrency)
When to use find() vs load ?
Hibernate - Spring integration problem
Loading the metadata of the table