我正在使用休眠4.2.21版本。我有部分实体,我使用了@Embedded和@Embeddable注释。当尝试运行项目时,它会给出一个异常;
属性映射具有错误的列数:com.demo.School.teacher 类型:对象
学校实体类
@Entity(name = "School")
public class{
public String schoolId;
public String schoolName;
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "teacherName",column = @Column(name = "teacherName")),
@AttributeOverride(name = "teacherPhone",column = @Column(name = "teacherPhone")),
})
@XmlElements({
@XmlElement(name = "TeacherU", type = TeacherU.class),
@XmlElement(name = "TeacherH", type = TeacherH.class)
})
public object teacher;
//getters and setters
}
教师(大学(实体类
@Embeddable
public class TeacherU {
public String teacherName;
public String teacherPhone;
//getters and setters
}
教师(高中(实体类
@Embeddable
public class TeacherH {
public String teacherName;
public String teacherPhone;
//getters and setters
}
不应将教师声明为对象,更改
public object teacher;
自
public Teacher teacher;