2010-11-12 67 views
1

我试图让这个映射工作休眠,但我得到这个奇怪的异常消息映射例外与CollectionOfElements

Could not determine type for: foo.ProcessUser, at table: ProcessUser_onetimeCodes, for columns: [org.hibernate.mapping.Column(processUser)]

@Entity 
public class ProcessUser { 

    @Setter 
    private List<OnetimeCodes> onetimeCodes; 

    @CollectionOfElements 
public List<OnetimeCodes> getOnetimeCodes() { 
    return onetimeCodes; 
    } 
} 


@Embeddable 
@Data 
public class OnetimeCodes { 

    @Parent 
    private ProcessUser processUser; 

    @Column(nullable=false) 
    @NotEmpty 
    private String password; 


    public OnetimeCodes(ProcessUser processUser, String password) { 
     this.processUser = processUser; 
     this.password = password; 
    } 
} 

任何人能发现什么是错在这里吗? 我有hibernate.hbm2ddl.autocreate

回答

2

我发现了错误。

您不能在其中一个类中的属性和另一个类中的getter上进行映射。他们应该匹配。

因此,我改变

@Embeddable 
@Data 
public class OnetimeCodes { 

    @Parent 
    private ProcessUser processUser; 

    @Column(nullable=false) 
    @NotEmpty 
    private String password; 


    public OnetimeCodes(ProcessUser processUser, String password) { 
     this.processUser = processUser; 
     this.password = password; 
    } 
} 

@Embeddable 
public class OnetimeCodes { 

    private ProcessUser processUser; 

    private String password; 

    public OnetimeCodes(ProcessUser processUser, String password) { 
     this.processUser = processUser; 
     this.password = password; 
    } 

    @Parent 
    public ProcessUser getProcessUser() { 
     return processUser; 
    } 

    public void setProcessUser(ProcessUser processUser) { 
     this.processUser = processUser; 
    } 

    @Column(nullable=false) 
    @NotEmpty 
    public String getPassword() { 
     return password; 
    } 

    public void setPassword(String password) { 
     this.password = password; 
    } 
} 

和中提琴。 如果你问我,这很愚蠢。

+0

该框架是愚蠢的。我有同样的问题。我的设置非常复杂(具有多对一关系的复合外键),我从来没有想到它就是这样。不仅框架的代码不好,文档也是如此,因为它永远不会让'@ EmbeddedId'放在getter上。 – tiktak 2015-01-18 00:29:59