【问题标题】:Help with exception in hibernate帮助解决休眠中的异常
【发布时间】:2011-07-21 08:54:21
【问题描述】:

我已将此 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;
    }
}

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

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

有什么帮助吗?

最好的问候, 瓦尔特·恩里克。

【问题讨论】:

  • 似乎是参加者提出了 Evento 类的问题。你能告诉我们 Evento 课程吗?
  • 顺便说一句,最好将代码(类名、方法名、变量名等)保持为英文。

标签: java hibernate jsp exception


【解决方案1】:

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

【讨论】:

【解决方案2】:

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

【讨论】:

  • 我遵循@Augusto 下面的建议,感谢您的帮助,它给了我一个领导。干杯。
猜你喜欢
  • 1970-01-01
  • 2018-01-09
  • 2010-10-25
  • 1970-01-01
  • 1970-01-01
  • 2018-10-01
  • 2013-09-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多