学习hibernate遇到的问题及解决方案

使用工具版本: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);

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值