2011-03-23 44 views
4

我有這樣的POJO映射到我的MySQL數據庫:幫助,在Hibernate例外

@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 

任何幫助?

此致敬禮, 瓦爾特恩裏克。

+0

這似乎是與參與問題Evento類。你能告訴我們Evento課嗎? – Puce 2011-03-23 14:33:01

+1

順便說一下,最好將代碼(類名,方法名,變量名等)保留爲英文。 – Puce 2011-03-23 14:34:10

回答

5

異常消息非常明確--Hibernate無法確定集合的元素類型Evento.participantespresentes。您需要聲明它是通用的(即List<Participantespresentes>)。

+0

感謝兄弟,這正是你說的,謝謝。 – 2011-03-23 15:11:27

+0

一個很好的解釋它也可以在這裏找到http://www.mkyong.com/hibernate/org-hibernate-annotationexception-collection-has-neither-generic-type-or-onetomany-targetentity/ – 2011-06-29 08:52:30

0

問題不在Participantespresentes中,而是在類Evento中。你在那裏有一個叫做參與者的屬性,但它沒有正確映射。如果沒有找到問題,請張貼Evento的代碼。

+0

我遵循下面的建議@Augusto,感謝您的幫助,它讓我領先。 乾杯。 – 2011-03-23 15:12:02