@Entity
@Table(name = "PERSON")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
public class Person {
@Id
@GeneratedValue
@Column(name = "PERSON_ID")
private Long personId;
@Column(name = "FIRSTNAME")
private String firstname;
@Column(name = "LASTNAME")
private String lastname;
// Constructors and Getter/Setter methods,
}
Employee class extends Person
@Entity
public class Employee extends Person {
@Transient
private Date joiningDate;
// Copy Constructors and Getter/Setter methods,
}
The Employee class has only a transient object So I am not sure about using of @DiscriminatorColumn and @DiscriminatorValue, When i tried without using Discriminator that throws error
session.save(employee);
I am trying to save Employee object that throws Unknown column 'DTYPE' in 'field list' error
I have encountered the same issue using EclipseLink and I have tried to use @discriminator annotation ... without success because in this solution, a specific column must be added in 2 tables.
I don't have the possibility to add columns in tables, so I have found following solution :
@Entity
@Table(name = "PERSON")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Person {
I have just changed inheritance type from SINGLE_TABLE to TABLE_PER_CLASS
I have found useful explanation on Thoughts on Java
Just for information, my 2 tables are in reality 1 table and a view on same table with 2 or 3 joins.
You should use @DiscriminatorColumn and @DiscriminatorValue. You can find a good example here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With