Skip to content

Commit bf5db4d

Browse files
committed
HHH-18829 Hibernate Core: use ID class generated by Hibernate Processor when class is not annotated with @IdClass, but have more than one member annotated with @id
1 parent 891ef63 commit bf5db4d

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,17 @@ private boolean mapAsIdClass(
483483
final ClassDetails classWithIdClass = inheritanceState.getClassWithIdClass( false );
484484
if ( classWithIdClass != null ) {
485485
final IdClass idClassAnn = classWithIdClass.getDirectAnnotationUsage( IdClass.class );
486-
final Class<?> idClassValue = idClassAnn.value();
487-
final ClassDetails compositeClass =
488-
getMetadataCollector().getSourceModelBuildingContext().getClassDetailsRegistry()
489-
.resolveClassDetails( idClassValue.getName() );
486+
final ClassDetails compositeClass;
487+
if ( idClassAnn == null ) {
488+
compositeClass = getMetadataCollector().getSourceModelBuildingContext()
489+
.getClassDetailsRegistry()
490+
.resolveClassDetails( inheritanceState.getClassDetails().getClassName() + "_$Id" );
491+
}
492+
else {
493+
final Class<?> idClassValue = idClassAnn.value();
494+
compositeClass = getMetadataCollector().getSourceModelBuildingContext()
495+
.getClassDetailsRegistry().resolveClassDetails( idClassValue.getName() );
496+
}
490497
final TypeDetails compositeType = new ClassTypeDetailsImpl( compositeClass, TypeDetails.Kind.CLASS );
491498
final TypeDetails classWithIdType = new ClassTypeDetailsImpl( classWithIdClass, TypeDetails.Kind.CLASS );
492499

hibernate-core/src/main/java/org/hibernate/boot/model/internal/InheritanceState.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.ArrayList;
88
import java.util.List;
99
import java.util.Map;
10+
import java.util.stream.Stream;
1011

1112
import org.hibernate.AnnotationException;
1213
import 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 );

0 commit comments

Comments
 (0)