1. 程式人生 > >Hinernate:org.hibernate.AnnotationException: No identifier specified for entity

Hinernate:org.hibernate.AnnotationException: No identifier specified for entity

使用hibernate的e-r對映pojo類的時候遇到org.hibernate.AnnotationException: No identifier specified for entity異常。可是entity類的註釋沒有問題,唯一的不正常的地方是這張表比較特殊沒有主鍵,好像在使用hibernate的對映表的時候entity類是必須要主鍵的,否則就會報出這個異常。
解決辦法自然是add一個主鍵進去,新增主鍵的神器就在我的上一篇文章中,這裡主要是對實體類的註釋,應該做新增
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "id", nullable = false
)
    private int id;