由于近期学习SSH框架 在整合Spring+Hibernate时文件配置错误导致自己耽误了一天的时间,进行一下总结,以提醒不要再踩这种坑。
原本我是这样配置的
<property name="mappingDirectoryLocations" value="classpath:com/myzy/web/bean" >
</property>
然后测试时就报:映射文件找不到的错误。
org.hibernate.MappingException: Unknown entity: com.myzy.web.bean.User
at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:781)
at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1520)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:100)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192)...........
在网上找了大把资料过后,任然没有头绪。后来仔细读了这位大佬https://www.cnblogs.com/liaojie970/p/4904781.html的博客过后
严重怀疑是自己查找hibernate映射文件的属性用错了。然后开始动工改,果然改了过后测试成功。(本人新手,有什么建议请多多指教。谢谢)
<!-- 引入orm元数据,指定orm元数据的包路径,在spring启动时将自动读取包中所有配置 -->
<property name="mappingLocations" value="classpath:com/myzy/web/entity/*.hbn.xml">
</property>