Hi,
I try to migrate from Hibernate 5.0.5 to 5.2.4.
I have a problem with inheritance. It seems to me that Hibernate 5.2.4 does not recognize a column in a subclass and I don't know why.
My class implementation (not changed!):
Code:
@Entity(name = "A_Object")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "DIS", discriminatorType = DiscriminatorType.STRING, length = 3)
@DiscriminatorValue("AD")
@Table(name = "A")
public class A {
...
private Integer nr = null;
@Column(name = "A_NR")
public Integer getNr() {
return nr;
}
public void setNr(Integer val) {
this.nr = val;
}
...
}
@Entity(name = "B_Object")
@DiscriminatorValue("BD")
@SecondaryTable(name = "B", pkJoinColumns = @PrimaryKeyJoinColumn(name = "B_A_ID"))
public class B extends A {
...
private Integer nr;
@Override
@Column(table="B", name = "B_NR")
public Integer getNr() {
return nr;
}
public void setNr(Integer val) {
this.nr = val;
}
...
}
When I try to save an instance of B, although B.nr is set (but not a.nr), in the trace the column "B_NR" is not included:
Code:
insert
into
TEST.A (A_COL1, A_COL_2, A_NR) // A_NR included! And set to "1", although a.nr is null and b.nr = "1"?!
values (?, ?,...)
insert
into
TEST.B (B_COL1, B_COL_2, ...) // B_NR not included!
values (?, ?,...)
The result is a ConstraintViolationException, because B_NR has a not-null constraint. (There is no constraint on A_NR)
When I rename B.getNr() to B.getNr2() so that it does not override A.getNr() any longer, everything works fine. A_NR is set to null, B_NR is set to "1". Hibernate recognizes the column B_NR and B_NR is included in the insert:
Code:
insert
into
TEST.A (A_COL1, A_COL_2, ..., A_NR) // A_NR included!
values (?, ?,...)
insert
into
TEST.B (B_COL1, B_COL_2, ..., B_NR) // B_NR included!
values (?, ?,...)
With Hibernate 5.0.5, this problem did not exist.
Can you help me please how to fix the problem?
Thank you in advance!
Btw:
Changing the implementation from B.setNr() to
Code:
public void setNr(Integer val) {
this.nr = val;
super.setNr(val);
}
does not solve the problem. Although a.nr and b.nr are set, the column B_NR is not detected/filled.