与Collection elements的Hibernate中的映射异常
-
09-10-2019 - |
题
我试图让这个映射工作,但是我得到了这个奇怪的异常消息
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.auto
上 create
解决方案
我发现了错误。
您不能在其中一个类别的属性和另一个属性中映射属性。他们应该匹配。
所以我改变了
@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;
}
}
和中提琴。如果你问我很愚蠢。
不隶属于 StackOverflow