JavaEar 专注于收集分享传播有价值的技术资料

Spring Data JPA / Hibernate "Unable to locate Attribute with the given name"

We have a problem with a Spring Web Application and Hibernate. It is written in Kotlin. We have an abstract Entity

@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

And some of those:

@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
        }

Note that "Lead" inherits directly from "AbstractContact". The Problem is with the property contact. The User Property, where Telephonist inherits directly from User, works fine.

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

We did it the same way before, where it works. Really no clue whats wrong.

2个回答

    最佳答案
  1. In my case, using pure java, the cause was that an abstract @MappedSuperClass defined abstract getter/setter methods according to an interface, but did not define the actual member field.

    The error went away after removing the getter/setter methods from the abstract class, there was no need for them after all. HTH

  2. 参考答案2
  3. A wider possibility is that you refactorized an attribute name but with an inconsistency in a:

    • getter and/or setter
    • @Query
    • @NamedEntityGraphs
    • @NamedQuery