{"record":{"id":"c39b97c54cb283cc","repo":"hibernate/hibernate-orm","slug":"no-default-constructor-for-entity","errorCode":null,"errorMessage":"No default constructor for entity","messagePattern":"No default constructor for entity","errorType":"exception","errorClass":"InstantiationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityInstantiatorPojoStandard.java","lineNumber":94,"sourceCode":"\t\t}\n\t\treturn entity;\n\n\t}\n\n\t@Override\n\tpublic boolean isInstance(Object object) {\n\t\treturn super.isInstance( object )\n\t\t\t// this one needed only for guessEntityMode()\n\t\t\t|| proxyInterface != null && proxyInterface.isInstance( object );\n\t}\n\n\t@Override\n\tpublic Object instantiate() {\n\t\tif ( isAbstract() ) {\n\t\t\tthrow new InstantiationException( \"Cannot instantiate abstract class or interface\", getMappedPojoClass() );\n\t\t}\n\t\telse if ( constructor == null ) {\n\t\t\tthrow new InstantiationException( \"No default constructor for entity\", getMappedPojoClass() );\n\t\t}\n\t\telse {\n\t\t\ttry {\n\t\t\t\treturn applyInterception( constructor.newInstance( (Object[]) null ) );\n\t\t\t}\n\t\t\tcatch ( Exception e ) {\n\t\t\t\tthrow new InstantiationException( \"Could not instantiate entity\", getMappedPojoClass(), e );\n\t\t\t}\n\t\t}\n\t}\n}\n","sourceCodeStart":76,"sourceCodeEnd":106,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EntityInstantiatorPojoStandard.java#L76-L106","documentation":"Thrown by EntityInstantiatorPojoStandard.instantiate() when the mapped POJO entity class has no no-arg constructor. During instantiator construction Hibernate calls ReflectHelper.getDefaultConstructor(mappedPojoClass); on PropertyNotFoundException it logs 'no default constructor' via CORE_LOGGER and stores null, so the failure surfaces at runtime the first time Hibernate must create an entity instance itself (loading, persisting a new instance, refresh of detached data).","triggerScenarios":"An @Entity class whose only constructors take arguments; persist() (not merge()) of a new instance when Hibernate still needs the default constructor for interception/enhancement; loading rows via em.find or queries for entities lacking a no-arg constructor.","commonSituations":"Kotlin data/regular classes without the kotlin-noarg or all-open plugin (JPA plugin); Lombok classes using @Builder/@AllArgsConstructor without @NoArgsConstructor; Java value-style entities with only canonical constructors; constructors made private for factory patterns.","solutions":["Add a no-arg constructor to the entity (public or protected), e.g. Lombok @NoArgsConstructor or a protected no-op constructor","For Kotlin, apply the kotlin.plugin.jpa / no-arg plugin so the compiler synthesizes the constructor","Keep argument constructors for business use but delegate to defaults from the no-arg one"],"exampleFix":"// before\n@Entity\npublic class Order {\n    private final String number;                 // only ctor takes args\n    public Order(String number) { this.number = number; }\n}\n\n// after\n@Entity\npublic class Order {\n    private String number;\n    protected Order() { }                        // for Hibernate\n    public Order(String number) { this.number = number; }\n}","handlingStrategy":"validation","validationCode":"// Fail fast if any mapped entity lacks a no-arg ctor\nfor ( EntityType<?> t : emf.getMetamodel().getEntities() ) {\n    Class<?> c = t.getJavaType();\n    if ( c != null ) {\n        try { c.getDeclaredConstructor(); }\n        catch (NoSuchMethodException e) { throw new IllegalStateException(\"Entity \" + c + \" has no no-arg constructor\"); }\n    }\n}","typeGuard":"static boolean hasNoArgConstructor(Class<?> c) {\n    try { c.getDeclaredConstructor(); return true; } catch (NoSuchMethodException e) { return false; }\n}","tryCatchPattern":"try {\n    session.persist(newEntity);\n}\ncatch ( org.hibernate.InstantiationException e ) {\n    if ( \"No default constructor for entity\".equals(e.getMessage()) ) {\n        throw new IllegalStateException(\"Add a no-arg constructor to \" + e.getMessage(), e);\n    }\n    throw e;\n}","preventionTips":["Give every @Entity a public/protected no-arg constructor (JPA requirement)","Kotlin: enable kotlin(\"plugin.jpa\") / all-open; Lombok: pair @Builder with @NoArgsConstructor","Add an architecture test (ArchUnit) asserting a no-arg constructor on all @Entity classes"],"tags":["hibernate","jpa","entity","no-arg-constructor","kotlin","lombok"],"backgroundTag":"missing-no-arg-constructor","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}