Hi,
I have an inehritance/overriding problem and I didn't find any solution on docs or internet.
Hibernate version:
core: 3.2.4-sp1
annotations: 3.3.0
Hi, I have these 3 classes:
Code:
@Entity
public class Father {
private int id;
private String comment;
@Id
public int getId() {
return id;
}
public String getComment() {
return comment;
}
public void setId(int id) {
this.id = id;
}
public void setComment(String comment) {
this.comment = comment;
}
@Override
public String toString() {
return getClass().getName() + "-> id:" + getId() + ", comment:" + getComment();
}
}
-------------------------------------------------------------------------------------
@Entity
public class Child extends Father {
}
-------------------------------------------------------------------------------------
@Entity
public class OverridenChild extends Father {
@Override
public String getComment() {
return super.getComment();
}
@Override
public void setComment(String comment) {
super.setComment(comment);
}
}
In the OverridenChild class, I want to override the comment property (for adding code or a validator annotation).
If I don't put a @Transient annotation on getComment(), I get the following exception:
Code:
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: org.test.OverridenChild column: comment (should be mapped with insert="false" update="false")
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:652)
at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:674)
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:696)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:450)
at org.hibernate.mapping.SingleTableSubclass.validate(SingleTableSubclass.java:43)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
at org.test.Test.<clinit>(Test.java:29)
If I put an @OverrideAttribute on comment, Hibernate complain that I'm trying to register the column comment 2 times.
It's very odd to need to add an @Transient annotation on a persistent property. Am'I missing something?
Thanks.