SSH整合,applicationContext.xml中配置hibernate映射文件问题

  今天在applicationContext.xml中配置sessionFactory时遇到了各种头疼的问题,现在总结一下:

  1.<property name="mappingDirectoryLocations"> 如果你的xxx.hbm.xml配置文件放在了src目录的包下面,要使用mappingDirectoryLocations管理映射文件,最好在<value>标签中的文件目录前加上classpath:

  如:

1 <property name="mappingDirectoryLocations">
2 <list>
3 <value>classpath:com/sims/*/model</value>
4 </list>
5 </property>

  因为今天写项目时,没有加classpath,用junit测试service完全没问题,但是放到了tomcat下面就出现了xxx is not mapped这样的异常。排查了好久……

  PS:当然,mappingDirectoryLocations是支持通配符的。

  2.如果在读取配置文件时,提示Unable to get the default Bean Validation factory或者带有validation字样的异常,那估计是少了这个配置:

1 <property name="javax.persistence.validation.mode">none</property>

  这是在hibernate.cfg.xml中的写法

但是,当我们进行SSH整合时,则需要在applicationContext.xml中配置Hibernate,那么我们需要在hibernateProperties下进行配置。同样的,加上上面一句配置即可。

1 <property name="hibernateProperties">
2             <props>
3                 <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
4                 <prop key="hibernate.show_sql">true</prop>
5                 <prop key="hibernate.format_sql">true</prop>
6                 <prop key="javax.persistence.validation.mode">none</prop>
7             </props>
8         </property>
原文地址:https://www.cnblogs.com/iridescent/p/3674396.html