File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed
hibernate-core/src/main/java/org/hibernate/boot/model/internal Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -481,10 +481,17 @@ private boolean mapAsIdClass(
481481 final ClassDetails classWithIdClass = inheritanceState .getClassWithIdClass ( false );
482482 if ( classWithIdClass != null ) {
483483 final IdClass idClassAnn = classWithIdClass .getDirectAnnotationUsage ( IdClass .class );
484- final Class <?> idClassValue = idClassAnn .value ();
485- final ClassDetails compositeClass =
486- getMetadataCollector ().getSourceModelBuildingContext ().getClassDetailsRegistry ()
487- .resolveClassDetails ( idClassValue .getName () );
484+ final ClassDetails compositeClass ;
485+ if ( idClassAnn == null ) {
486+ compositeClass = getMetadataCollector ().getSourceModelBuildingContext ()
487+ .getClassDetailsRegistry ()
488+ .resolveClassDetails ( inheritanceState .getClassDetails ().getClassName () + "_$Id" );
489+ }
490+ else {
491+ final Class <?> idClassValue = idClassAnn .value ();
492+ compositeClass = getMetadataCollector ().getSourceModelBuildingContext ()
493+ .getClassDetailsRegistry ().resolveClassDetails ( idClassValue .getName () );
494+ }
488495 final TypeDetails compositeType = new ClassTypeDetailsImpl ( compositeClass , TypeDetails .Kind .CLASS );
489496 final TypeDetails classWithIdType = new ClassTypeDetailsImpl ( classWithIdClass , TypeDetails .Kind .CLASS );
490497
Original file line number Diff line number Diff line change 77import java .util .ArrayList ;
88import java .util .List ;
99import java .util .Map ;
10+ import java .util .stream .Stream ;
1011
1112import org .hibernate .AnnotationException ;
1213import org .hibernate .boot .spi .AccessType ;
@@ -183,6 +184,13 @@ else if ( classDetails.hasDirectAnnotationUsage( IdClass.class ) ) {
183184 return classDetails ;
184185 }
185186 else {
187+ final long count = Stream .concat (
188+ classDetails .getFields ().stream (),
189+ classDetails .getMethods ().stream ()
190+ ).filter ( t -> t .hasDirectAnnotationUsage ( Id .class ) ).count ();
191+ if ( count > 1 ) {
192+ return classDetails ;
193+ }
186194 final InheritanceState state = getSuperclassInheritanceState ( classDetails , inheritanceStatePerClass );
187195 if ( state != null ) {
188196 return state .getClassWithIdClass ( true );
You can’t perform that action at this time.
0 commit comments