1、替换JAR包
使用新版本的JAR包:
hibernate-commons-annotations-4.0.2.Final.jar
hibernate-core-4.2.15.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
jboss-logging-3.1.0.GA.jar
替换原JAR包:
hibernate3.jar
2、修改applicationContext.xml
将其内部的有关hibernate3的配置,全部替换为hibernate4:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- ... -->
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
否则,运行时可能会报错:java.lang.ClassNotFoundException: org.hibernate.cache.CacheProvider
3、替换INTEGER,去除编译错误
将Hibernate.INTEGER替换为StandardBasicTypes.INTEGER。
否则,编译器会报错:INTEGER cannot be resolved or is not a field
4、去除的Propagation.NOT_SUPPORTED
xxxDaoImpl.java,如果原有如下的语句:@Transactional(propagation = Propagation.NOT_SUPPORTED)
需要将它们全部去掉。并且要检查一下,为xxxDaoImpl类,加上@Transactional注解。
否则,运行时报错:org.hibernate.HibernateException: No Session found for current thread