2014-02-26 189 views
0

我收到的時候我試圖創建一個多對一映射休眠:無法多對一關係

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

SpecialtygetDoctors()@OneToMany(mappedBy = "specialty")

來註釋