org.hibernate.MappingException: Unknown entity: annotations.Users

前端 未结 19 1602
情歌与酒
情歌与酒 2020-12-01 07:11

Consider the hierarchy :

\"enter

And the following classes and xml :

19条回答
  •  旧巷少年郎
    2020-12-01 07:52

    Instead of using HibernateUtil.java, to create sessionfactory object, you should use this:

    SessionFactory sessionFactory=new AnnotationConfiguration().configure().buildSessionFactory();
    

    Because in order to avoid the exception, you'll have to declare the class object in HibernateUtil.java file as configuration.addAnnotatedClass(Student_Info.class); which looks dumb because we have provided the entry already in hibernate.cfg.xml file.

    To use the AnnotationConfiguration class you'll have to add a jar to your project build path: http://www.java2s.com/Code/Jar/h/Downloadhibernate353jar.htm

提交回复
热议问题