I’m extending an entity which doesn’t auto generate its id.
I want to ‘override’ its generation strategy to AUTO in my derived class.
Something like this.
@Entity
public class Base {
@Id
@Column(name = "id")
public Integer getId() {
return id;
}
}
@Entity
public class Extender extends Base {
@GeneratedValue(strategy = GenerationType.AUTO)
public Integer getId() {
return super.getId();
}
}
This is what I get when I try to do it:
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: Extender column: id (should be mapped with insert="false" update="false")
I understand why this happens, but I need to know if there is a valid way to do it.
Thanks,
It is impossible, because you can define primary key only once and GeneratedValue can be only where primary key is defined. And same with words from specification: