diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java index 9cd76b70c9..8889cd07a3 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java @@ -781,6 +781,12 @@ public class PropertyBinder { propertyBinder.setInheritanceStatePerClass( inheritanceStatePerClass ); propertyBinder.setId( !entityBinder.isIgnoreIdAnnotations() && hasIdAnnotation( property ) ); + if ( isPropertyOfRegularEmbeddable( propertyHolder, isComponentEmbedded ) + && property.hasDirectAnnotationUsage(Id.class)) { + throw new AnnotationException("Member '" + property.getName() + + "' of embeddable class " + propertyHolder.getClassName() + " is annotated '@Id'"); + } + final LazyGroup lazyGroupAnnotation = property.getDirectAnnotationUsage( LazyGroup.class ); if ( lazyGroupAnnotation != null ) { propertyBinder.setLazyGroup( lazyGroupAnnotation.value() ); @@ -805,6 +811,12 @@ public class PropertyBinder { addNaturalIds( inSecondPass, property, columns, joinColumns, context ); } + private static boolean isPropertyOfRegularEmbeddable(PropertyHolder propertyHolder, boolean isComponentEmbedded) { + return propertyHolder.isComponent() // it's a field of some sort of composite value + && !propertyHolder.isInIdClass() // it's not a field of an id class + && !isComponentEmbedded; // it's not an entity field matching a field of the id class + } + private static AnnotatedColumns bindProperty( PropertyHolder propertyHolder, Nullability nullability, diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Location.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Location.java index 46490d0a26..6d2058af3f 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Location.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Location.java @@ -8,7 +8,6 @@ import java.io.Serializable; /** * @author Emmanuel Bernard */ -@SuppressWarnings("serial") public class Location implements Serializable { public double longitude; public double latitude; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/orphan/onetoone/embedded/OneToOneLazyOrphanRemovalInEmbeddedEntityTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/orphan/onetoone/embedded/OneToOneLazyOrphanRemovalInEmbeddedEntityTest.java index bb6433e194..e7ef506f1d 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/orphan/onetoone/embedded/OneToOneLazyOrphanRemovalInEmbeddedEntityTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/orphan/onetoone/embedded/OneToOneLazyOrphanRemovalInEmbeddedEntityTest.java @@ -113,7 +113,7 @@ public class OneToOneLazyOrphanRemovalInEmbeddedEntityTest { @Embeddable public static class Car { - @Id + @Column(insertable = false, updatable = false) private Integer id; // represents a unidirectional one-to-one