我試圖在Hibernate中使用JPA @Embeddable
。實體和嵌入式都有一個屬性命名id
:Hibernate嵌入式:未找到組件屬性
@MappedSuperclass
public abstract class A {
@Id
@GeneratedValue
long id;
}
@Embeddable
public class B extends A {
}
@Entity
public class C extends A {
B b;
}
這就提出了一個org.hibernate.MappingException: component property not found: id
。
我想避免使用@AttributeOverrides
。我因此試圖設置spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.DefaultComponentSafeNamingStrategy
(我正在使用Spring Boot)。這沒有任何效果(同樣的例外)。然而,我懷疑該設置被忽略,因爲指定一個不存在的類不會引發異常。
但奇怪的是,即使有這種變異
@Entity
public class C extends A {
@Embedded
@AttributeOverrides({
@AttributeOverride(name="id", column = @Column(name="b_id")),
})
B b;
}
我仍然得到同樣的錯誤。