I have a question about inheritance in JPA, is it possible to do this Hierarchy using JOINED strategy?
Here my code:
@Entity
@Table(name = "PERSON")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "DTYPE", discriminatorType = DiscriminatorType.STRING, length = 4)
public abstract class Person implements Serializable {
...
}
@Entity
@Table(name = "EMPLOYEE")
@DiscriminatorValue(value="EMPL")
public abstract class Employee extends Person implements Serializable{
...
}
@Entity
@Table(name="CLIENT")
@DiscriminatorValue(value="CLIE")
public class Client extends Person implements Serializable{
...
}
@Entity
@Table(name="TEACHER")
@DiscriminatorValue(value="TEAC")
public class Teacher extends Employee implements Serializable{
...
}
After the above hierarchy, I tried to make a query using JPQL, this is the query:
@Entity
@Table(name="FICHA_EVALUACION")
public class SheetEvaluation implements Serializable{
@OneToOne
private Teacher teacher;
}
This code run from a main
Query query = entityManager.createQuery("SELECT f FROM SheetEvaluation f, Teacher teac, Employee emp, Person per WHERE f.teacher.id = teac.id and teac.id = emp.id and emp.id = per.id");
List<SheetEvaluation> sheetEvaluations = query.getResultList();
for (SheetEvaluation sheetEvaluation : sheetEvaluations ) {
System.out.println(" Teacher Name= " + sheetEvaluation .getTeacher().getName());
}
when I run the query throws me the following error
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'employee1_.DTYPE' in 'field list'
Please if you have any idea about the type of error obtained much I appreciate your support.
Best Regards