使用工具版本:Eclipse Java EE IDE for Web Developers.Version: Neon.3 Release (4.6.3),
hibernate版本:hibernate-release-5.2.12.Final
JUnit4测试单元版本:junit-4.12(由于自4.8版本以后,JUbit4.jar包中并不包含hamcrest-core-1.3.jar和hamcrest-core-1.3-sources.jar这两个包,所以需要单独下载)
MySQL版本:mysql-5.7.17-winx64
问题描述1:org.hibernate.MappingException: Unknown entity: com.wch.fhibernatemodel.vo.Employee
at org.hibernate.metamodel.internal.MetamodelImpl.entityPersister(MetamodelImpl.java:620)
at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1636)
重点是 Unknown entity问题,找不到实体
解决方法:
因为版本问题:Hibernate4版本的SessionFactory实例构建的步骤是这样的(也是很多学习资料的通用范本):
V4版:
//Configuration就是代表着hibernate的那个xml配置文件对象,如果configure方法中没有参数的话,默认是就是hibernate.cfg.xml。
Configuration conf = new Configuration().configure();
//服务注册,这是使用创建者模式,根据配置文件中的配置字段来构建注册服务(这应该是hibernate架构中注册服务的通用流程)。
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().
applySettings(conf.getProperties()).build();
//使用实例化好了的注册服务,使用Configuration中的工厂模式实例化了SessionFactory
SessionFactory sf = conf.buildSessionFactory(serviceRegistry);