2010-10-28 27 views
5

Tôi đang gặp việc thiết kế sau cho dự án chế độ ngủ đông của tôi:@ManyToMany trong một MappedSuperclass trừu tượng

@MappedSuperclass 
public abstract class User { 
    private List<Profil> profile; 

    @ManyToMany (targetEntity=Profil.class) 
    public List<Profil> getProfile(){ 
     return profile; 
    } 
    public void setProfile(List<Profil> profile) { 
     this.profile = profile; 
    } 
} 

@Entity 
@Table(name="kunde") 
public class Kunde extends User { 
    private Date birthdate; 
    @Column(name="birthdate") 
    @Temporal(TemporalType.TIMESTAMP) 
    public Date getBirthdate() { 
     return birthdate; 
    } 
    public void setBirthdate(Date birthdate) { 
     this.birthdate= birthdate; 
    } 
} 

@Entity 
@Table(name="employee") 
public class Employee extends User { 
    private Date startdate; 
    @Column(name="startdate") 
    @Temporal(TemporalType.TIMESTAMP) 
    public Date getStartdate() { 
     return startdate; 
    } 
    public void setStartdate(Date startdate) { 
     this.startdate= startdate; 
    } 
} 

Như bạn có thể thấy, tài mũ một mối quan hệ ManyToMany Về Hồ Sơ.

@Entity 
@Table(name="profil") 
public class Profil extends GObject { 
    private List<User> user; 

    @ManyToMany(mappedBy = "profile", targetEntity = User.class) 
    public List<User> getUser(){ 
     return user; 
    } 
    public void setUser(List<User> user){ 
     this.user = user; 
    } 
} 

Nếu bây giờ tôi cố gắng tạo ra một nhân viên, tôi nhận được một ngoại lệ Hibernate:

org.hibernate.AnnotationException: Sử dụng của @OneToMany hoặc @ManyToMany nhắm mục tiêu một lớp unmapped: de .ke.objects.bo.profile.Profil.user [de.ke.objects.bo.user.User]

Làm cách nào tôi có thể sử dụng mối quan hệ ManyToMany với Cấu hình trên người dùng cấp trên, vì vậy nó hoạt động cho Kunde và Empl oyee?

Xin cảm ơn trước.

+0

Xin chào, bạn đã có thể giải quyết vấn đề này chưa? Tôi đang đối mặt với cùng một vấn đề. – tarkikshah

Trả lời

3

Sự cố là do tham chiếu đến Người dùng, không phải là thực thể. Khóa ngoại chỉ có thể tham chiếu một bảng. Hoặc sử dụng @ManyToAny, có thể xử lý nhiều bảng, hoặc @Inheritance (strategy = InheritanceType.SINGLE_TABLE), sẽ đưa tất cả các thực thể vào một bảng.

Đây là tài liệu về thừa kế ở chế độ ngủ đông: http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#d0e1168

Các vấn đề liên quan