1

我试图让这个映射工作,但我收到这个奇怪的异常消息

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

4

1 回答 1

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;
    }
}

和中提琴。如果你问我,那就太愚蠢了。

于 2010-11-12T16:02:27.473 回答