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 @@ -482,10 +482,17 @@ private boolean mapAsIdClass(
482482 final ClassDetails classWithIdClass = inheritanceState .getClassWithIdClass ( false );
483483 if ( classWithIdClass != null ) {
484484 final IdClass idClassAnn = classWithIdClass .getDirectAnnotationUsage ( IdClass .class );
485- final Class <?> idClassValue = idClassAnn .value ();
486- final ClassDetails compositeClass =
487- getMetadataCollector ().getSourceModelBuildingContext ().getClassDetailsRegistry ()
488- .resolveClassDetails ( idClassValue .getName () );
485+ final ClassDetails compositeClass ;
486+ if ( idClassAnn == null ) {
487+ compositeClass = getMetadataCollector ().getSourceModelBuildingContext ()
488+ .getClassDetailsRegistry ()
489+ .resolveClassDetails ( inheritanceState .getClassDetails ().getClassName () + "_$Id" );
490+ }
491+ else {
492+ final Class <?> idClassValue = idClassAnn .value ();
493+ compositeClass = getMetadataCollector ().getSourceModelBuildingContext ()
494+ .getClassDetailsRegistry ().resolveClassDetails ( idClassValue .getName () );
495+ }
489496 final TypeDetails compositeType = new ClassTypeDetailsImpl ( compositeClass , TypeDetails .Kind .CLASS );
490497 final TypeDetails classWithIdType = new ClassTypeDetailsImpl ( classWithIdClass , TypeDetails .Kind .CLASS );
491498
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