{"record":{"id":"355f3bbf0ef8e134","repo":"hibernate/hibernate-orm","slug":"invalid-class-annotated-both-entity-and-embed","errorCode":null,"errorMessage":"Invalid class annotated both '@Entity' and '@Embeddable': '{}'","messagePattern":"Invalid class annotated both '@Entity' and '@Embeddable': '(.+?)'","errorType":"exception","errorClass":"AnnotationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java","lineNumber":1243,"sourceCode":"\tprivate final Map<String,AnnotatedClassType> annotatedClassTypeMap = new HashMap<>();\n\n\t@Override\n\tpublic AnnotatedClassType getClassType(ClassDetails clazz) {\n\t\tfinal var type = annotatedClassTypeMap.get( clazz.getName() );\n\t\treturn type == null ? addClassType( clazz ) : type;\n\t}\n\n\t@Override\n\tpublic AnnotatedClassType addClassType(ClassDetails clazz) {\n\t\tfinal var type = getAnnotatedClassType( clazz );\n\t\tannotatedClassTypeMap.put( clazz.getName(), type );\n\t\treturn type;\n\t}\n\n\tprivate static AnnotatedClassType getAnnotatedClassType(ClassDetails clazz) {\n\t\tif ( isEntity( clazz) ) {\n\t\t\tif ( isEmbeddable( clazz ) ) {\n\t\t\t\tthrow new AnnotationException( \"Invalid class annotated both '@Entity' and '@Embeddable': '\" + clazz.getName() + \"'\" );\n\t\t\t}\n\t\t\telse if ( isMappedSuperclass( clazz ) ) {\n\t\t\t\tthrow new AnnotationException( \"Invalid class annotated both '@Entity' and '@MappedSuperclass': '\" + clazz.getName() + \"'\" );\n\t\t\t}\n\t\t\treturn AnnotatedClassType.ENTITY;\n\t\t}\n\t\telse if ( isEmbeddable( clazz ) ) {\n\t\t\tif ( isMappedSuperclass( clazz ) ) {\n\t\t\t\tthrow new AnnotationException( \"Invalid class annotated both '@Embeddable' and '@MappedSuperclass': '\" + clazz.getName() + \"'\" );\n\t\t\t}\n\t\t\treturn AnnotatedClassType.EMBEDDABLE;\n\t\t}\n\t\telse if ( isMappedSuperclass( clazz ) ) {\n\t\t\treturn AnnotatedClassType.MAPPED_SUPERCLASS;\n\t\t}\n\t\telse if ( clazz.hasDirectAnnotationUsage( Imported.class ) ) {\n\t\t\treturn AnnotatedClassType.IMPORTED;\n\t\t}","sourceCodeStart":1225,"sourceCodeEnd":1261,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java#L1225-L1261","documentation":"Error \"Invalid class annotated both '@Entity' and '@Embeddable': '{}'\" thrown in hibernate/hibernate-orm.","triggerScenarios":"A class carries a combination of type annotations that are mutually exclusive.","commonSituations":"Annotating one class with @Entity plus @Embeddable or @MappedSuperclass, or @Embeddable plus @MappedSuperclass, e.g. after refactoring an entity hierarchy.","solutions":["Remove either @Entity or @Embeddable from the class; a class cannot be both an entity and an embeddable.","If the class is used as an embedded component, keep only @Embeddable; if it needs its own identity, keep only @Entity.","Check for conflicting annotations introduced via both the class and a superclass or interface default."],"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"}