gpt4 book ai didi

java - 帮助解决 hibernate 中的异常

转载 作者:搜寻专家 更新时间:2023-11-01 02:32:37 24 4
gpt4 key购买 nike

我将这个 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

有什么帮助吗?

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

最佳答案

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

关于java - 帮助解决 hibernate 中的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5406677/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com