帮助解决休眠中的异常

发布于 2024-10-25 22:11:34 字数 2089 浏览 0 评论 0原文

我将此 POJO 映射到我的 MySQL 数据库:

@Entity
@Table(name = "participantespresentes", catalog = "tagit")
public class Participantespresentes implements java.io.Serializable {

    private ParticipantespresentesId id;
    private Evento evento;
    private Usuario usuario;
    private boolean status;

    public Participantespresentes() {
    }

    public Participantespresentes(ParticipantespresentesId id, Evento evento, Usuario usuario, boolean status) {
        this.id = id;
        this.evento = evento;
        this.usuario = usuario;
        this.status = status;
    }

    @EmbeddedId
    @AttributeOverrides({
        @AttributeOverride(name = "idUsuario", column =
        @Column(name = "idUsuario", nullable = false)),
        @AttributeOverride(name = "idEvento", column =
        @Column(name = "idEvento", nullable = false))})
    public ParticipantespresentesId getId() {
        return this.id;
    }

    public void setId(ParticipantespresentesId id) {
        this.id = id;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "idEvento", nullable = false, insertable = false, updatable = false)
    public Evento getEvento() {
        return this.evento;
    }

    public void setEvento(Evento evento) {
        this.evento = evento;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "idUsuario", nullable = false, insertable = false, updatable = false)
    public Usuario getUsuario() {
        return this.usuario;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }

    @Column(name = "status", nullable = false)
    public boolean isStatus() {
        return this.status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }
}

每次我尝试使用 hibernate 执行任何操作时,都会启动此异常:

Initial SessionFactory creation failed.org.hibernate.AnnotationException: Collection has neither generic type or OneToMany.targetEntity() defined: com.bytecode.entities.Evento.participantespresentes

有帮助吗?

此致, 瓦尔特·恩里克.

i have this POJO mapped to my MySQL database:

@Entity
@Table(name = "participantespresentes", catalog = "tagit")
public class Participantespresentes implements java.io.Serializable {

    private ParticipantespresentesId id;
    private Evento evento;
    private Usuario usuario;
    private boolean status;

    public Participantespresentes() {
    }

    public Participantespresentes(ParticipantespresentesId id, Evento evento, Usuario usuario, boolean status) {
        this.id = id;
        this.evento = evento;
        this.usuario = usuario;
        this.status = status;
    }

    @EmbeddedId
    @AttributeOverrides({
        @AttributeOverride(name = "idUsuario", column =
        @Column(name = "idUsuario", nullable = false)),
        @AttributeOverride(name = "idEvento", column =
        @Column(name = "idEvento", nullable = false))})
    public ParticipantespresentesId getId() {
        return this.id;
    }

    public void setId(ParticipantespresentesId id) {
        this.id = id;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "idEvento", nullable = false, insertable = false, updatable = false)
    public Evento getEvento() {
        return this.evento;
    }

    public void setEvento(Evento evento) {
        this.evento = evento;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "idUsuario", nullable = false, insertable = false, updatable = false)
    public Usuario getUsuario() {
        return this.usuario;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }

    @Column(name = "status", nullable = false)
    public boolean isStatus() {
        return this.status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }
}

And everytime that i try to execute any operation with hibernate, launch this exception:

Initial SessionFactory creation failed.org.hibernate.AnnotationException: Collection has neither generic type or OneToMany.targetEntity() defined: com.bytecode.entities.Evento.participantespresentes

Any help ?

Best regards,
Valter Henrique.

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

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

发布评论

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

评论(2

泼猴你往哪里跑 2024-11-01 22:11:34

异常消息非常清楚 - Hibernate 无法确定集合 Evento.participantespresentes 的元素类型。您需要将其声明为通用(即 List)。

Exception message is pretty clear - Hibernate cannot determine element type of collection Evento.participantespresentes. You need to declare it as generic (i.e. as List<Participantespresentes>).

零度℉ 2024-11-01 22:11:34

问题不在于 Participantespresentes,而在于 Evento 类。您有一个名为participantespresentes的属性,但它没有正确映射。如果没有发现问题,请贴出Evento的代码。

The problem is not in Participantespresentes, but in the class Evento. You have there an attribute called participantespresentes, but it's not mapped properly. If don't find the problem, please post the code of Evento.

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