Skip to content

Commit a16ce73

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 a6d5f2d commit a16ce73

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
@@ -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

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)