Spring Data JPA / Hibernate "Unable to locate Attribute with the given name"
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
Heady
Currently actigve as CTO @ Uniwunder, a company aiming to help students to develop their full potential by providing upskilling-resources and helping them to find perfect job-fits. We are mainly developing Web Applications with Kotlin, Spring and Angular. The applications are either Online-Tools for customers, data-warehouse applications and B2B-Solutions in context of our student-plattforms. I studied Computer Media Science @ TU Dresden before Co-Founding Uniwunder. Personally my interests mostly lie in product development and workflow-tools.
Updated on June 14, 2022Comments
-
Heady almost 2 years
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.
-
Julio Villane almost 7 yearsin my case was @NamedEntityGraph