• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate

 
Chinki Jhurani
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May be you are not sending in the key correctly. This will probably me moved to the appropriate forum.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64961
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post your code?
 
Chinki Jhurani
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please help.... i'm waiting for reply..
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64961
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic