mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-16 08:05:05 +00:00
HHH-18626 fix error for @Id annotation in @Embeddable class
This commit is contained in:
parent
e9bf523ce1
commit
fc2b1b9854
@ -781,6 +781,12 @@ private static void buildProperty(
|
||||
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 @@ private static void buildProperty(
|
||||
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,
|
||||
|
@ -8,7 +8,6 @@
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class Location implements Serializable {
|
||||
public double longitude;
|
||||
public double latitude;
|
||||
|
@ -113,7 +113,7 @@ public void setCar(Car car) {
|
||||
@Embeddable
|
||||
public static class Car {
|
||||
|
||||
@Id
|
||||
@Column(insertable = false, updatable = false)
|
||||
private Integer id;
|
||||
|
||||
// represents a unidirectional one-to-one
|
||||
|
Loading…
x
Reference in New Issue
Block a user