Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extend an entity class in JPA throws Unknown column 'DTYPE' in 'field list' error

@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

like image 311
Cork Kochi Avatar asked Apr 25 '17 19:04

Cork Kochi


2 Answers

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.

like image 118
schlebe Avatar answered Sep 20 '22 18:09

schlebe


You should use @DiscriminatorColumn and @DiscriminatorValue. You can find a good example here.

like image 37
Daniel Andres Pelaez Lopez Avatar answered Sep 16 '22 18:09

Daniel Andres Pelaez Lopez