关于Hibernate出现找不到实体类(Exception in thread "main" org.hibernate.MappingException: Unknown entity)
2017-09-29 14:27
721 查看
关于这个问题卡了两天,一直没有调试过去,原因是因为hibernate的包没有按照资料上的4.x版本,升级到了5.x版本的
不同版本的获取SessionFactory的方法不一样。
例如Hibernate 4.3 其中的一种 获取SessionFactory的方法
//实例化configuration
Configuration con=new Configuration().configure();
//实例化ServiceRegistry
ServiceRegistry service=new StandardServiceRegistryBuilder().applySettings(con.getProperties()).build();
//创建SessionFactory实例
SessionFactory fac=con.buildSessionFactory(service);
而Hibernate 5.1 的获取SessionFactory的方法
StandardServiceRegistry serviceRegistry=new StandardServiceRegistryBuilder().configure().build();
本文参考了卓先紳博客文章http://blog.csdn.net/dreameer_dd/article/details/52024016
不同版本的获取SessionFactory的方法不一样。
例如Hibernate 4.3 其中的一种 获取SessionFactory的方法
//实例化configuration
Configuration con=new Configuration().configure();
//实例化ServiceRegistry
ServiceRegistry service=new StandardServiceRegistryBuilder().applySettings(con.getProperties()).build();
//创建SessionFactory实例
SessionFactory fac=con.buildSessionFactory(service);
而Hibernate 5.1 的获取SessionFactory的方法
StandardServiceRegistry serviceRegistry=new StandardServiceRegistryBuilder().configure().build();
SessionFactory sessionFactory=new MetadataSources(serviceRegistry).buildMetadata().buildSessionFactory();
本文参考了卓先紳博客文章http://blog.csdn.net/dreameer_dd/article/details/52024016
相关文章推荐
- 关于Hibernate出现找不到实体类(Exception in thread "main" org.hibernate.MappingException: Unknown entity)
- Exception in thread "main" org.hibernate.MappingException: Unknown entity: com.pojo.User
- Exception in thread "main" org.hibernate.MappingException: Unknown entity: com.hibernate.domain.User
- Exception in thread "main" org.hibernate.MappingException: Unknown entity: com.mao.PersonSet
- Hibernate 5.X 版本中Exception in thread "main" org.hibernate.MappingException: Unknown entity: cn.xxx.p
- Exception in thread "main" org.hibernate.MappingException: invalid configuration
- Exception in thread "main" org.hibernate.MappingException: Unknown entity: XXX
- Exception in thread "main" org.hibernate.MappingException: You may only specify a cache for root
- Exception in thread "main" org.hibernate.MappingException: Unknown entity: org.model.Kcb
- Exception in thread "main" org.hibernate.InvalidMappingException: Unable to read XML
- Exception in thread "main" org.hibernate.MappingException: Unknown entity:
- Exception in thread "main" org.hibernate.MappingNotFoundException
- 关于hibernate中的错误:Exception in thread "main" org.hibernate.hql.internal.ast.QuerySyntaxException: tb_e
- Exception in thread "main" org.hibernate.InvalidMappingException: Could not pars
- Exception in thread "main" org.hibernate.MappingException: You may only specify a cache for root <cl
- Exception in thread "main" org.hibernate.MappingNotFoundException: resource: com.xzhl.user.model/Stu
- 关于反编译apk出现Exception in thread "main" java.lang.ClassCastException: ....
- 使用PDFBox,出现Exception in thread "main" java.lang.NoSuchMethodError: org.fontbox.cmap.CMapParser.parse
- Exception in thread "main" org.hibernate.HibernateException: No CurrentSessionContext configured!
- Exception in thread "main" org.hibernate.TransientObjectException: object references an unsaved tran