当我尝试创建ManyToOne映射时,我收到以下错误
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: org.hibernate.MappingException: Could not determine type for: edu.cs157b.hibernate.Specialty, at table: DOCTOR_INFO, for columns: [org.hibernate.mapping.Column(specialty)]
这是我试图映射的两个类
医生
package edu.cs157b.hibernate;
import java.util.ArrayList;
import javax.persistence.*;
@Entity
@Table(name="DOCTOR_INFO")
@NamedQueries (
{
@NamedQuery(name = "Doctor.getAll", query = "from Doctor"),
@NamedQuery(name = "Doctor.findByName", query = "from Doctor where name = :name")
}
)
public class Doctor implements Person {
private int id;
private String name;
private int appointment_id;
@ManyToOne (fetch = FetchType.EAGER)
@JoinColumn(name="specialty_id")
private Specialty specialty;
@Id
@GeneratedValue
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(unique=true)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Specialty getSpecialty() {
return specialty;
}
public void setSpecialty(Specialty specialty) {
this.specialty = specialty;
}
public int getAppointment_id() {
return appointment_id;
}
public void setAppointment_id(int appointment_id) {
this.appointment_id = appointment_id;
}
}
特种
package edu.cs157b.hibernate;
import java.util.ArrayList;
import javax.persistence.*;
@Entity
@Table(name="SPECIALTY_INFO")
@NamedQueries (
{
@NamedQuery(name = "Specialty.getAll", query = "from Specialty"),
@NamedQuery(name = "Specialty.findByName", query = "from Specialty where name = :name")
}
)
public class Specialty {
private ArrayList<Doctor> doctors;
private int id;
private String name;
@Id
@GeneratedValue
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(unique=true)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ArrayList<Doctor> getDoctors() {
return doctors;
}
public void setDoctors(ArrayList<Doctor> doctors) {
this.doctors = doctors;
}
}
答案 0 :(得分:0)
getDoctors()
中的 Specialty
应使用@OneToMany(mappedBy = "specialty")