使用 CollectionOfElements 映射休眠中的异常

发布于 2024-10-02 07:19:13 字数 786 浏览 0 评论 0原文

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

无法确定类型:foo.ProcessUser,表:ProcessUser_onetimeCodes,列:[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;
    }
}

有人能发现这里出了什么问题吗? 我在 create 上有 hibernate.hbm2ddl.auto

I am trying to get this mapping to work, but I get this strange exception message

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

Can anyone spot whats wrong here?
I have hibernate.hbm2ddl.auto on create

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

假面具 2024-10-09 07:19:13

我发现了错误。

您不能在一个类中的属性上进行映射,而在另一个类中的 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;
    }
}

中提琴。
如果你问我的话,我非常愚蠢。

I found the error.

You cannot have mapping on the attribute in one of the classes, and on getters on the other. They should match.

So I changed

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

to

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

and viola.
Very stupid if you ask me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文