I'm trying to use JPA @Embeddable
s with Hibernate. The entity and the embeddable both have a property named id
:
@MappedSuperclass
public abstract class A {
@Id
@GeneratedValue
long id;
}
@Embeddable
public class B extends A {
}
@Entity
public class C extends A {
B b;
}
This raises a org.hibernate.MappingException: component property not found: id
.
I want to avoid using @AttributeOverrides
. I thus tried to set spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.DefaultComponentSafeNamingStrategy
(I'm using Spring Boot). This did not have any effect (same exception). I, however, suspect that the setting is beeing ignored because specifying a non-existing class doesn't raise an exception.
The strange thing is, even with this variant
@Entity
public class C extends A {
@Embedded
@AttributeOverrides( {
@AttributeOverride(name="id", column = @Column(name="b_id") ),
} )
B b;
}
I still get the same error.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…