I have a lot of mapped entities, and all of them extends from an abstract class BaseEntityImpl
.
In this class, I have 1 attribute company, annotated like this:
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name = "id_company", nullable = false)
public Company getCompany() {
return company;
}
In only one of the subclasses ( Company
to be precise), I want this attribute to be NULLEABLE.
But overriding the setter
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name = "id_company", nullable = true)
@Override
public Company getCompany() {
return company;
}
leads me to this error:
Caused by: org.hibernate.MappingException: Duplicate property mapping of company found in ar.com.test.entity.Company
Is there any way, besides not extending for this class, and explicitly defining all attributes/getters/setters in the Company class to achieve this?
Thank you so much!
Have you tried looking at @AssociationOverride ?
@Entity
@AssociationOverride(name="company",
joinColumns=@JoinColumn(name="id_company", nullable=true))
public class Company extends BaseEntityImpl {
....
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.