Skip to content

Commit efcea35

Browse files
committed
HHH-18626 fix error for @id annotation in @embeddable class
1 parent d81b284 commit efcea35

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,12 @@ private static void buildProperty(
781781
propertyBinder.setInheritanceStatePerClass( inheritanceStatePerClass );
782782
propertyBinder.setId( !entityBinder.isIgnoreIdAnnotations() && hasIdAnnotation( property ) );
783783

784+
if ( isPropertyOfRegularEmbeddable( propertyHolder, isComponentEmbedded )
785+
&& property.hasDirectAnnotationUsage(Id.class)) {
786+
throw new AnnotationException("Member '" + property.getName()
787+
+ "' of embeddable class " + propertyHolder.getClassName() + " is annotated '@Id'");
788+
}
789+
784790
final LazyGroup lazyGroupAnnotation = property.getDirectAnnotationUsage( LazyGroup.class );
785791
if ( lazyGroupAnnotation != null ) {
786792
propertyBinder.setLazyGroup( lazyGroupAnnotation.value() );
@@ -805,6 +811,12 @@ private static void buildProperty(
805811
addNaturalIds( inSecondPass, property, columns, joinColumns, context );
806812
}
807813

814+
private static boolean isPropertyOfRegularEmbeddable(PropertyHolder propertyHolder, boolean isComponentEmbedded) {
815+
return propertyHolder.isComponent() // it's a field of some sort of composite value
816+
&& !propertyHolder.isInIdClass() // it's not a field of an id class
817+
&& !isComponentEmbedded; // it's not an entity field matching a field of the id class
818+
}
819+
808820
private static AnnotatedColumns bindProperty(
809821
PropertyHolder propertyHolder,
810822
Nullability nullability,

hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Location.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
/**
99
* @author Emmanuel Bernard
1010
*/
11-
@SuppressWarnings("serial")
1211
public class Location implements Serializable {
1312
public double longitude;
1413
public double latitude;

hibernate-core/src/test/java/org/hibernate/orm/test/inheritance/InheritanceJunctionExistsPredicateTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/*
2-
* Hibernate, Relational Persistence for Idiomatic Java
3-
*
4-
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
5-
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
2+
* SPDX-License-Identifier: LGPL-2.1-or-later
3+
* Copyright Red Hat Inc. and Hibernate Authors
64
*/
75
package org.hibernate.orm.test.inheritance;
86

hibernate-core/src/test/java/org/hibernate/orm/test/jpa/orphan/onetoone/embedded/OneToOneLazyOrphanRemovalInEmbeddedEntityTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ public void setCar(Car car) {
113113
@Embeddable
114114
public static class Car {
115115

116-
@Id
117116
private Integer id;
118117

119118
// represents a unidirectional one-to-one

hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/instantiation/MatchingConstructorTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/*
2+
* SPDX-License-Identifier: LGPL-2.1-or-later
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
15
package org.hibernate.orm.test.query.hql.instantiation;
26

37
import org.hibernate.annotations.Imported;

0 commit comments

Comments
 (0)