org.hibernate.AnnotationException: No identifier specified for entity

来源:互联网 发布:类似知乎的网站 编辑:程序博客网 时间:2024/06/02 02:22

转载自:http://blog.sina.com.cn/s/blog_529aacbd0100z8u2.html

使用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;


    


0 0
原创粉丝点击