0

I am using hibernate 4.2.21 version. I have partial entities and I used @Embedded and @Embeddable annotations. When trying to run project , it gives an exception;

property mapping has wrong number of columns: com.demo.School.teacher type: object

School entity class

@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 
}

Teacher (University) entity class

@Embeddable
public class TeacherU {
   public String teacherName;
   public String teacherPhone;

   //getters and setters 
}

Teacher (High School) entity class

@Embeddable
public class TeacherH {
   public String teacherName;
   public String teacherPhone;

   //getters and setters 
}

1 Answers1

0

Teacher shouldn't be declared as an Object, change

public object teacher;

to

public Teacher teacher;
L.dev
  • 93
  • 2
  • 9
  • I edited the question because it has two different types of Teacher entities that I didn't mention, sorry. – muhammed ozbilici Oct 07 '19 at 14:15
  • 1
    Teacher must be declared as concrete class in School. Use discriminator column if you want to have two different teachers in one table. – L.dev Oct 07 '19 at 14:28
  • Is there another solution ? Because, these are generated classes from .xsd files with wsimport tool and I can't change class signature. – muhammed ozbilici Oct 07 '19 at 14:46