• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ObjectNotFoundException when trying to add an object in the database.

 
luke brown
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

i am not able to run the following program completely.
firstly it is able to create the employee as needed. But when i am trying to add a new employee in the table , its throwing exception Also i found that the following expression :

employeeID = (Integer) session.save(employee);

is returning value 0.So please let me know where i am going wrong.






output:

First Name: Zara Last Name: Ali Salary: 1000
First Name: Daisy Last Name: Das Salary: 5000
First Name: John Last Name: Paul Salary: 10000
+++++++++++++++++
***********************
First Name: Zara Last Name: Ali Salary: 1000
First Name: Daisy Last Name: Das Salary: 5000
First Name: John Last Name: Paul Salary: 10000
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [my.first.hib.Employee#0]
at org.hibernate.internal.SessionFactoryImpl$1$1.handleEntityNotFound(SessionFactoryImpl.java:253)
at org.hibernate.proxy.AbstractLazyInitializer.checkTargetState(AbstractLazyInitializer.java:262)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:176)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:286)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:185)
at my.first.hib.Employee_$$_jvstaa5_0.toString(Employee_$$_jvstaa5_0.java)
at java.lang.String.valueOf(Unknown Source)
at java.io.PrintStream.println(Unknown Source)
at my.first.hib.ManageEmployee.updateEmployee(ManageEmployee.java:105)
at my.first.hib.ManageEmployee.main(ManageEmployee.java:
 
Volodymyr Lysenko
Ranch Hand
Posts: 512
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have id property in your Employee entity. It should be like this:

If you mapped primary key then show your entity Employee.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic