Hibernate: No Row With The Given Identifier Exists


When there is a foreign key but the referenced row does not existed, or has been deleted, hibernate would throw an exception like this:


org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.firstwap.geofencing.pojo.VehicleGeofence#546]
at org.hibernate.ObjectNotFoundException.throwIfNull(ObjectNotFoundException.java:27)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:65)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:98)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:158)
at com.firstwap.geofencing.pojo.VehicleGeofence$$EnhancerByCGLIB$$3f798ceb.getGpsVehicle(<generated>)
at com.firstwap.geofencing.socket.GeofenceParser.setAlarmLog(GeofenceParser.java:409)


If it's a bug, the code should handle this exception properly, either by marking the data as corrupted or notifying end-user about it.
If it's not a bug, setting the attribute not-found as "ignore" in the many-to-one hibernate mapping would eliminate the exception.


<many-to-one name="employee" class="Employee"
column="CITY_ID" not-null="false" lazy="false" not-found="ignore">
</many-to-one>




16 comments: (+add yours?)

Praveen said...
This comment has been removed by the author.
Praveen said...

after i did NotFoundAction.IGNORE teh same error happends does any one know

Unknown said...

Check all columns that have foreign key relationship

S Charan Kumar said...

but my foreign key is compiste key based on two columns, i specifed as you mentioned but while updating is is giving Exception "deleted object is re-saved because there is an cascade asssciation"

Unknown said...

Your new exception tell us that Hibernate cannot save the child object because the exactly same object has been already deleted before.
This condition usually happens when you accidentally removed (setting as null) the child object from the parent object and then set it again with the previous child object. You may try to read the code again to see which line has the condition, or try setting the mapping to cascade="none", but you will have to manually save each of the child objects.

SiM said...

this helped me a lot :-) thanks and keep up your good work !

Anonymous said...

it helped me

Pascal Maniraho said...

thank you very much, I had this error for so many hours...

Anonymous said...

Great! Saved my time.

guess what said...

Thank you... this was very helpful

Anonymous said...

Thanks, very helpful

Anonymous said...

Great..It saced my time..Thanks

Axilees said...

Dude, You are my hero!
not-found="ignore" - save my day!

Diljeet said...

Thanks a lot.. You saved my time.. :)

Anonymous said...

Thanks a lot it was helpfull!!!!

Anonymous said...

Thanks Man! great help.