Pages

Thursday

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:

  1. This comment has been removed by the author.

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

    ReplyDelete
  3. Check all columns that have foreign key relationship

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

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

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

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

    ReplyDelete
  8. Great! Saved my time.

    ReplyDelete
  9. Thank you... this was very helpful

    ReplyDelete
  10. Thanks, very helpful

    ReplyDelete
  11. Great..It saced my time..Thanks

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

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

    ReplyDelete
  14. Thanks a lot it was helpfull!!!!

    ReplyDelete
  15. Thanks Man! great help.

    ReplyDelete