2017-07-06 68 views
2

我在困難中停留在Hibernate組合鍵中的問題。 錯誤:org.hibernate.MappingException:無法確定類型爲:java.util.Set,在表:IDP_UserManagerMapping,列:[org.hibernate.mapping.Column(idps)]。我試過機智@transient和其他的東西,但沒有效果請幫助。Hibernate中的組合鍵錯誤org.hibernate.MappingException:無法確定類型爲:java.util.Set,

public class IDPUserManagerMapping implements Serializable { 
    private Long id; 
    private Users user; 
    private Users manager; 
    private Users assessor; 

    @OneToMany(fetch = FetchType.LAZY) 
    @JoinColumns({ 
     @JoinColumn(name="user_id" ,referencedColumnName = "user_id"), 
     @JoinColumn(name="manager_id" ,referencedColumnName = "manager_id") 
     ,@JoinColumn(name="assessor_id" ,referencedColumnName = "assessor_id") 
    }) 
    @Cascade(CascadeType.ALL) 
    private Set<IDPMaster> idps = null; 

    @Id 
    @SequenceGenerator(sequenceName="idp_usermanagermapping_id_seq",name="idp_usermanagermapping_id_seq_gen") 
    @GeneratedValue(generator="idp_usermanagermapping_id_seq_gen") 
    @Column(name="id",nullable=false,unique=true,updatable=false) 
    public Long getId() { 
     return id; 
    } 
    public void setId(Long id) { 
     this.id = id; 
    } 

    public Set<IDPMaster> getIdps() { 
     return idps; 
    } 
    public void setIdps(Set<IDPMaster> idps) { 
     this.idps = idps; 
    } 
     @ManyToOne(fetch=FetchType.LAZY) 
    @JoinColumn(name="user_id",nullable=false) 
    public Users getUser() { 
     return user; 
    } 
    public void setUser(Users user) { 
     this.user = user; 
    } 

    @ManyToOne(fetch=FetchType.LAZY) 
    @JoinColumn(name="manager_id",nullable=false) 
    public Users getManager() { 
     return manager; 
    } 
    public void setManager(Users manager) { 
     this.manager = manager; 
    } 

    @ManyToOne(fetch=FetchType.LAZY) 
    @JoinColumn(name="assessor_id") 
    public Users getAssessor() { 
     return assessor; 
    } 
    public void setAssessor(Users assessor) { 
     this.assessor = assessor; 
    } 
    } 

第二實體

public class IDPMaster implements Serializable { 
    private Long id; 
    private Users managerUser; 
    private Users assessorUser; 
    private Users idpUsers; 
    @Id 
    @SequenceGenerator(name="idp_master_id_seq_gen",sequenceName="idp_master_id_seq") 
    @GeneratedValue(generator="idp_master_id_seq_gen") 
    @Column(name="id",nullable=false,unique=true) 
    public Long getId() { 
     return id; 
    } 
    public void setId(Long id) { 
     this.id = id; 
    } 
    @ManyToOne(fetch=FetchType.LAZY) 
    @JoinColumn(name="user_id",nullable=false) 
    public Users getIdpUsers() { 
     return idpUsers; 
    } 
    public void setIdpUsers(Users idpUsers) { 
     this.idpUsers = idpUsers; 
    } 
    @OneToOne(fetch=FetchType.LAZY) 
    @JoinColumn(name="manager_id") 
    public Users getManagerUser() { 
     return managerUser; 
    } 
    public void setManagerUser(Users managerUser) { 
     this.managerUser = managerUser; 
    } 

    @OneToOne(fetch=FetchType.LAZY) 
    @JoinColumn(name="assessor_id") 
    public Users getAssessorUser() { 
     return assessorUser; 
    } 
    public void setAssessorUser(Users assessorUser) { 
     this.assessorUser = assessorUser; 
    } 
    } 

回答

2

你應該將註釋

@OneToMany(fetch = FetchType.LAZY) 
    @JoinColumns({ 
     @JoinColumn(name="user_id" ,referencedColumnName = "user_id"), 
     @JoinColumn(name="manager_id" ,referencedColumnName = "manager_id") 
     ,@JoinColumn(name="assessor_id" ,referencedColumnName = "assessor_id") 
    }) 
    @Cascade(CascadeType.ALL) 

private Set<IDPMaster> idps = null;public Set<IDPMaster> getIdps()吸氣

休眠通過ID列分析說明,如果您使用的getter的註解你應該使用getter annotat無處不在。

+0

但是,這些都是瞬態成員,所以我把它保留在現場。如果我這樣做,那麼我必須將它標記爲'@瞬態'註釋。那麼它會在這裏工作? – ThinkTank

相關問題