Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate -org.hibernate.ObjectNotFoundException why?

 
bikasit babu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am new to the Hibernate . I am trying some coding in it. Finally it ends up with exception which i am not able to resolve it so i need your help . i am pastin you with all the code please find out where i am making the mistake as i am unable to

The First thing in hibernate which i have make is a pojo class name Person.java file

Person.java


after that i have copied the hibernate.cfg.xml into my src folder
hibernate.cfg.xml


where i have changed all the necessary fields

then
i have copied the Person.hbm.xml file into my package com.bika
changes the necessary fields
Person.hbm.xml


afterdone it all i finally write the Manager.java class to insert or to do the ORM operation

color=red]Manager.java[ [/color]



as it it is successfully inserted in db but while retrieving the data in console i have written another java class named Manager1.java but getting Exception
Manager1.java


and the exception as follows

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
.....Manager1...
1
Hibernate: select person0_.PERSON_ID as PERSON1_0_0_, person0_.firstName as firstName0_0_, person0_.lastName as lastName0_0_, person0_.age as age0_0_ from PERSON person0_ where person0_.PERSON_ID=?
Exception in thread "main" org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.bika.Person#1]
at org.hibernate.impl.SessionFactoryImpl$2.handleEntityNotFound(SessionFactoryImpl.java:419)
at org.hibernate.proxy.AbstractLazyInitializer.checkTargetState(AbstractLazyInitializer.java:154)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:143)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:174)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
at com.bika.Person_$$_javassist_0.getFirstName(Person_$$_javassist_0.java)
at com.bika.Manager1.main(Manager1.java:23)



can any body please help whats the flaws i am going through
I will really greatful to you all

Thanks in advance
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This configuration states that the id will auto generated. So I'm guessing that whatever Person object got inserted into the database has a different id than what you are querying it with via the session.load method. Have you looked into the DB to see what the row contents are?
 
bikasit babu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi jaikiran,

thanks for replying . Yeah i checked into db .so no row was there . But i tried it once again by inserting a row by commenting (p1.setId(1)) Id .as the row is inserted

In db it is showing as

EDIT PERSON_ID FIRSTNAME LASTNAME AGE
Edit 1 Bikasit Babu 22

but while retrieving again the same problem

same exception
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure you are running that load program against the same database and table which contains those newly added rows? Can you also post the most recent stacktrace?
 
bikasit babu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi jaikiran,
Ya i am checking that one on Oracle db.
after one more run on insertion i got in console this

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Hibernate: select hibernate_sequence.nextval from dual
Hibernate: insert into PERSON (firstName, lastName, age, PERSON_ID) values (?, ?, ?, ?)

and data has been reinserted

upon saving one more person object

i got the console as

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Hibernate: select hibernate_sequence.nextval from dual
Hibernate: select hibernate_sequence.nextval from dual
Hibernate: insert into PERSON (firstName, lastName, age, PERSON_ID) values (?, ?, ?, ?)
Hibernate: insert into PERSON (firstName, lastName, age, PERSON_ID) values (?, ?, ?, ?)


on retrieving(by running Manager1.java)

i got same output on consol

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
.....Manager1...
1
Hibernate: select person0_.PERSON_ID as PERSON1_0_0_, person0_.firstName as firstName0_0_, person0_.lastName as lastName0_0_, person0_.age as age0_0_ from PERSON person0_ where person0_.PERSON_ID=?
Exception in thread "main" org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.bika.Person#1]
at org.hibernate.impl.SessionFactoryImpl$2.handleEntityNotFound(SessionFactoryImpl.java:419)
at org.hibernate.proxy.AbstractLazyInitializer.checkTargetState(AbstractLazyInitializer.java:154)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:143)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:174)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
at com.bika.Person_$$_javassist_0.getFirstName(Person_$$_javassist_0.java)
at com.bika.Manager1.main(Manager1.java:23)


One thing i didnt understand .while inserting the data is showing in database all the inserted data but upon running Manage1.java which is for retrieval if you recheck on db it shows no data on Person table
in db it shows as no record found on retrieval. whats going on actually



 
bikasit babu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jaikiran,
well on the reply what i have written. I don't know why the table has been drop or deleted from db while running Manager1.java .Please give me answer for that.

Finally i got the output on console by changing hibernate.hbm.cfg file
hibernate.cfg.xml



by changing itg ffrom create to update why ? can you explain
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This property executes files containing SQL DML statements executed during the SessionFactory creation (So when the application starts in most cases, assuming a Singleton SessionFactory)

This property is not meant for production. It is a developer tool.


Validate: validate the schema, makes no changes to the database.
update: update the schema.
create: creates the schema, destroying previous data.
create-drop: drop the schema at the end of the session.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic