{"record":{"id":"ce8e90d77cf9a857","repo":"hibernate/hibernate-orm","slug":"entity-may-not-be-null","errorCode":null,"errorMessage":"Entity may not be null","messagePattern":"Entity may not be null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java","lineNumber":1694,"sourceCode":"\t\t\tnullAssociations = setOfSize( INIT_COLL_SIZE );\n\t\t}\n\t\tnullAssociations.add( new AssociationKey( ownerKey, propertyName ) );\n\t}\n\n\t@Override\n\tpublic boolean isPropertyNull(EntityKey ownerKey, String propertyName) {\n\t\treturn nullAssociations != null\n\t\t\t&& nullAssociations.contains( new AssociationKey( ownerKey, propertyName ) );\n\t}\n\n\tprivate void clearNullProperties() {\n\t\tnullAssociations = null;\n\t}\n\n\t@Override\n\tpublic boolean isReadOnly(Object entityOrProxy) {\n\t\tif ( entityOrProxy == null ) {\n\t\t\tthrow new IllegalArgumentException( \"Entity may not be null\" );\n\t\t}\n\n\t\tfinal var lazyInitializer = extractLazyInitializer( entityOrProxy );\n\t\tif ( lazyInitializer != null ) {\n\t\t\treturn lazyInitializer.isReadOnly();\n\t\t}\n\t\telse {\n\t\t\tfinal var ee = getEntry( entityOrProxy );\n\t\t\tif ( ee == null ) {\n\t\t\t\tthrow new UnmanagedObjectException( \"Given entity is not associated with the persistence context\" );\n\t\t\t}\n\t\t\treturn ee.isReadOnly();\n\t\t}\n\t}\n\n\t@Override\n\tpublic void setReadOnly(Object object, boolean readOnly) {\n\t\tif ( object == null ) {","sourceCodeStart":1676,"sourceCodeEnd":1712,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java#L1676-L1712","documentation":"Error \"Entity may not be null\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java:1694 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a non-null entity instance to the persistence-context operation","Guard against null before calling getEntry/removeEntity on the persistence context"],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}