春季数据JPA /hibernate“无法find给定名称的属性”

我们有一个Spring Web应用程序和Hibernate的问题。 它写在Kotlin。 我们有一个抽象的实体

@Inheritance(strategy = InheritanceType.JOINED) abstract @Entity class ContactLogEntry protected constructor() { @GeneratedValue @Id val id: Long = 0 @ManyToOne @JoinColumn protected lateinit var _contact: AbstractContact open val contact: AbstractContact? get() = _contact @ManyToOne protected var _user: User? = null open val user: User? get() = _user 

其中一些:

 @Entity class MailLogEntry() : ContactLogEntry() { override var contact: Lead get() = super.contact as Lead set(value) { super._contact = value } override var user: Telephonist get() = super.user as Telephonist private set(value) { super._user = value } 

请注意,“Lead”直接从“AbstractContact”inheritance。 问题是与财产contact 。 电话用户直接从用户身上inheritance的用户属性工作正常。

我们Unable to locate Attribute with the the given name [contact] on this ManagedType (PATH to ContactLogEntry)

我们之前也是这样做的,它在哪里工作。 真的不知道什么是错的。

在我的情况下,使用纯java,原因是一个抽象的@MappedSuperClass根据接口定义抽象的getter / setter方法,但没有定义实际的成员字段。

从抽象类中移除getter / setter方法后,错误消失了,毕竟没有必要这样做。 HTH

更广泛的可能性是,你重构了一个属性名称,但在一个不一致的情况下:

  • 吸气剂和/或凝结剂
  • @Query
  • @NamedEntityGraphs
  • @NamedQuery