{"record":{"id":"1a1dc3400ea4f728","repo":"hibernate/hibernate-orm","slug":"no-row-with-the-given-identifier-exists-for-entity","errorCode":null,"errorMessage":"No row with the given identifier exists for entity \" + infoString( entityName, identifier )","messagePattern":"No row with the given identifier exists for entity \" \\+ infoString\\( entityName, identifier \\)","errorType":"exception","errorClass":"UnresolvableObjectException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/UnresolvableObjectException.java","lineNumber":47,"sourceCode":"\tprotected UnresolvableObjectException(String message, Object identifier, String clazz) {\n\t\tsuper( message );\n\t\tthis.identifier = identifier;\n\t\tthis.entityName = clazz;\n\t}\n\n\t/**\n\t * Factory method for building and throwing an {@code UnresolvableObjectException} if the entity is null.\n\t *\n\t * @param entity The entity to check for nullness\n\t * @param identifier The identifier of the entity\n\t * @param entityName The name of the entity\n\t *\n\t * @throws UnresolvableObjectException Thrown if entity is null\n\t */\n\tpublic static void throwIfNull(Object entity, Object identifier, String entityName)\n\t\t\tthrows UnresolvableObjectException {\n\t\tif ( entity == null ) {\n\t\t\tthrow new UnresolvableObjectException( identifier, entityName );\n\t\t}\n\t}\n\n\tpublic Object getIdentifier() {\n\t\treturn identifier;\n\t}\n\n\tpublic String getEntityName() {\n\t\treturn entityName;\n\t}\n\n\t@Override\n\tpublic String getMessage() {\n\t\treturn super.getMessage() + \" for entity \" + infoString( entityName, identifier );\n\t}\n\n}\n","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/UnresolvableObjectException.java#L29-L65","documentation":"UnresolvableObjectException (with the full message \"No row with the given identifier exists for entity <Entity>#<id>\", assembled in getMessage() at UnresolvableObjectException.java:61) is thrown when a load by identifier finds no database row. The throwIfNull factory (UnresolvableObjectException.java:44-49) is invoked by loader code after a row comes back null; its subclass ObjectNotFoundException covers the lazy-proxy variant of the same situation. It almost always means the row was deleted by another transaction, or the id simply does not exist, while your persistence context still references it.","triggerScenarios":"session.load()/EntityManager.getReference() returning a proxy whose underlying row is deleted before first access; loading an association whose target row was removed concurrently; calling internal persister loads with a stale identifier taken from a detached object or a cached reference.","commonSituations":"Long-lived optimistic conversations where another user/session deleted the row; admin cleanup jobs removing rows still referenced by in-flight requests; UI code caching ids past their lifetime; tests that assume seeded data that was rolled back.","solutions":["Switch from load()/getReference() to get()/find() and null-check the result - find() returns null instead of throwing for a missing row","If you must keep the lazy reference, wrap first access in try/catch for ObjectNotFoundException (subclass of UnresolvableObjectException) and recover by treating the entity as deleted","Re-fetch the id's existence with a cheap exists-query before dereferencing stale references in long conversations","For concurrent-delete hotspots, consider a short pessimistic lock when loading so the row cannot vanish mid-transaction"],"exampleFix":"// before - throws UnresolvableObjectException/ObjectNotFoundException when the row is gone\nOrder order = session.load(Order.class, orderId);\norder.getTotal();\n\n// after - returns null for a missing row, handle explicitly\nOrder order = session.get(Order.class, orderId);\nif (order == null) {\n    return ResponseEntity.notFound().build();\n}","handlingStrategy":"try-catch","validationCode":"// before dereferencing a possibly-stale reference, verify existence with find()\nOrder order = em.find(Order.class, orderId);\nif (order == null) {\n    // handle 'row gone' as a normal business case\n}","typeGuard":null,"tryCatchPattern":"try {\n    order.getTotal(); // lazy access on a load()/getReference() proxy\n} catch (ObjectNotFoundException | UnresolvableObjectException e) {\n    // treat as deleted: drop from UI / return 410 Gone\n}","preventionTips":["Prefer get()/find() over load()/getReference() whenever the row may legitimately be missing","Do not cache entity ids longer than the lifecycle of the row they point to","Handle deletes centrally (soft-delete or domain events) so other sessions learn rows vanished"],"tags":["entity-loading","deleted-row","lazy-initialization","concurrency","hibernate"],"backgroundTag":"entity-not-found","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}