привет, я только что создал приложение, которое сохраняет данные в таблицах с однозначным отображением
всякий раз, когда я пытаюсь сохранить данные в таблице, я получаю следующую ошибку.
`Exception in thread "main" org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.mapping.onetoone.Instructor.theInstructorDetail references an unknown entity: com.mapping.onetoone.InstructorDetail`
вот мой код с аннотациями @Entity и OneToOne
Instructor.java
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private int id;
@Column(name="first_name")
private String firstName;
@Column(name="last_name")
private String lastName;
@Column(name="email")
private String email;
@OneToOne(cascade=CascadeType.ALL )
@JoinColumn(name="instructor_detail_id")
private InstructorDetail theInstructorDetail;
public Instructor(){}
public Instructor(String firstName, String lastName, String email) {
super();
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public InstructorDetail getTheInstructorDetail() {
return theInstructorDetail;
}
public void setTheInstructorDetail(InstructorDetail theInstructorDetail) {
this.theInstructorDetail = theInstructorDetail;
}
@Override
public String toString() {
return "Instructor [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", email=" + email
+ ", theInstructorDetail=" + theInstructorDetail + "]";
}
вот мой InstructorDetail.java
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private int id;
@Column(name="youtube_channel")
private String youTubeChannel;
@Column(name="hobby")
private String hobby;
public InstructorDetail(){}
public InstructorDetail(String youTubeChannel, String hobby) {
super();
this.youTubeChannel = youTubeChannel;
this.hobby = hobby;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getYouTubeChannel() {
return youTubeChannel;
}
public void setYouTubeChannel(String youTubeChannel) {
this.youTubeChannel = youTubeChannel;
}
public String getHobby() {
return hobby;
}
public void setHobby(String hobby) {
this.hobby = hobby;
}
@Override
public String toString() {
return "InstructorDetail [id=" + id + ", youTubeChannel=" + youTubeChannel + ", hobby=" + hobby + "]";
}
CreateInstructor.java
public static void main(String[] args) {
SessionFactory factory=new Configuration().configure("hibernate1.cfg.xml")
.addAnnotatedClass(Instructor.class).buildSessionFactory();
Session session = factory.getCurrentSession();
try
{
System.out.println("Object created. Now creating Instructor object...");
Instructor ins=new Instructor("elon", "musk", "elonmusk@hotmail.com");
System.out.println("Creating InstructorDetail object...");
InstructorDetail theInstructorDetail=new InstructorDetail("vella Panti Adda", "Acting");
ins.setTheInstructorDetail(theInstructorDetail);
session.beginTransaction();
System.out.println("Saving data....");
session.save(ins);
session.getTransaction().commit();
System.out.println("Data saved!");
}
finally
{
factory.close();
}
}
может кто-нибудь мне помочь.