Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java hibernate中的单表策略继承_Java_Hibernate - Fatal编程技术网

Java hibernate中的单表策略继承

Java hibernate中的单表策略继承,java,hibernate,Java,Hibernate,我将使用三个简单的Person、Teacher和Student类在hibernate中进行简单的继承 这是我的父类(Person.java) 我的Teacher.javaClass: @Entity @DiscriminatorValue(value = "Teacher") public class Teacher extends Person implements Serializable { private String teacherDegree; public St

我将使用三个简单的
Person
Teacher
Student
类在hibernate中进行简单的继承

这是我的父类(
Person.java

我的
Teacher.java
Class:

@Entity
@DiscriminatorValue(value = "Teacher")
public class Teacher extends Person implements Serializable {

    private String teacherDegree;

    public String getTeacherDegree() {
        return teacherDegree;
    }

    public void setTeacherDegree(String teacherDegree) {
        this.teacherDegree = teacherDegree;
    }
}
还有我的
Student.java
课程:

@Entity
@DiscriminatorValue(value = "Student")
public class Student extends Person implements Serializable {

    private String studentCollege;

    public String getStudentCollege() {
        return studentCollege;
    }

    public void setStudentCollege(String studentCollege) {
        this.studentCollege = studentCollege;
    }
}
休眠配置:

...
        <property name="hibernate.hbm2ddl.auto">update</property>
        <property name="hibernate.current_session_context_class">thread</property>
        <mapping class="com.abc.Person"/>
        <mapping class="com.abc.Teacher"/>
        <mapping class="com.abc.Student"/>
...
但我有一个错误:

ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Type) values ('NewYork', 'Teacher ABC', 'phd', 'Teacher')' at line 1

同样作为惯例,你应该遵循以下风格。我现在记不起来了,但我想你需要某种形式的转义来填补列名中的空白

@DiscriminatorColumn(name = "PERSON_TYPE" , discriminatorType = DiscriminatorType.STRING)

有时,遵守大多数社区的编码习惯会更容易。

不确定您是否有权(取决于您的基础数据库)使用带空格的鉴别器列名。您还可以使用hibernate属性来显示sql,这使调试更容易。..true
ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Type) values ('NewYork', 'Teacher ABC', 'phd', 'Teacher')' at line 1
@DiscriminatorColumn(name = "PERSON_TYPE" , discriminatorType = DiscriminatorType.STRING)