【问题标题】:Property mapping has wrong number of columns属性映射的列数错误
【发布时间】:2019-10-07 13:44:39
【问题描述】:

我使用的是休眠 4.2.21 版本。我有部分实体,我使用了 @Embedded 和 @Embeddable 注释。尝试运行 project 时,它给出了异常;

属性映射的列数错误: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 
}

【问题讨论】:

    标签: hibernate embeddable


    【解决方案1】:

    教师不应该被声明为对象,改变

    public object teacher;
    

    到

    public Teacher teacher;
    

    【讨论】:

    • 我编辑了这个问题,因为它有两种不同类型的教师实体,我没有提到,抱歉。
    • 教师必须在学校声明为具体班级。如果您想在一张表中有两个不同的老师,请使用鉴别器列。
    • 还有其他解决方案吗?因为,这些是使用 wsimport 工具从 .xsd 文件生成的类,我无法更改类签名。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-23
    • 2019-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多