帮助解决休眠中的异常
我将此 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
异常消息非常清楚 - 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. asList<Participantespresentes>
).问题不在于 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.