Я пытаюсь сопоставить индивидуальное сопоставление в JPA, здесь, я взял отношения между учеником и контактом, у каждого ученика есть контакт.Объект с внутренним классом для создания объекта
я есть создать студенческий объект следующим образом,
@Entity
@Table(name="TBL_STUDENT")
public class Student implements Serializable{
public Student(){ }
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="ID")
private Integer studentId;
@OneToOne(targetEntity=StudentContact.class,fetch=FetchType.LAZY)
@JoinColumn(name="CONTACT_ID")
private StudentContact contact;
....
....
....
}
Теперь компания StudentContact следующим образом,
@Entity
@Table(name="TBL_STD_CONTACT")
public class StudentContact extends Serializable{
public StudentContact(){ }
@Id
@Column(name="ID")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer contactId;
...
...
// all the properties mapped,
public static class Builder{
private Integer contactId;
private String phoneNo;
private String streetAddr;
....
// all the properties as same as StudentContact
public Builder(String val){
this.city = val;
}
public Builder setContactId(Integer contactId) {
this.contactId = contactId;
return this;
}
// rest all the setter methods are like the above, having return type Builder
public StudentContact build(){
return new StudentContact(this);
}
}
private StudentContact(Builder builder){
this.contactId = builder.contactId;
this.city = builder.city;
this.phoneNo = builder.phoneNo;
.......
...
}
}
В приведенном выше StudentContact Entity вы можете увидеть, я создал внутренний Builder класс, у которого ответственность заключается в том, чтобы построить объект StudentContact, используя его метод «сборки», который вы можете увидеть в нижеуказанном классе StudentTest
Теперь у меня есть написан класс StudentTest который имеет основной метод следующим образом,
public class StudentTest {
public static void main(String [] args){
try{
StudentDAO dao = new StudentDAO();
Student student = dao.getEntity(110);
StudentContact contact = new StudentContact.Builder("Bhubaneshwar")
.setPhoneNo("9867342313")
.setPinCode("400392")
.setState("Odhisha").build();
student.setContact(contact);
dao.updateEntity(student);
}catch(Exception e){
e.printStackTrace();
}
}
Когда я бегу StudentTest из Netbeans IDE, это дает как ошибка
Exception in thread "main" java.lang.VerifyError: Constructor must call super() or this() before return in method com.entities.StudentContact.<init>()V at offset 0
Я не могу понять эту ошибку, является ли эта ошибка это потому, что для внутреннего класса, который я создал в классе StudentContact,
Как я могу решить эту проблему,
Даже если я написал super() или this() в моем собственном конструкторе StudentContact, все равно он дает ошибку –
У вас есть другие проблемы; StudentContact _extends_ Serializable - один –