spring升级到3.1.1 hibernate升级到4备忘
年初两个版本刚刚发布,还处于“血淋淋”的边缘,花了两天时间把所做的基于sh的一个框架进行升级,其过程有些纠结,写在这里做一备忘。
为什么要升级?升级的理由一个是hibernate4支持multi-tenant多租户模式,对于提供saas应用的项目来说,有这个与没这个有很大不同,尽管我已经在一个项目中实现了多租户模式,跟hibernate要做的第二种模式类似;另一个理由就是spring支持servlet3.0,并且对提供cache api,速度当然是主要考虑点。
没想到遇到很多问题,按网络流行语说是有点“蛋疼”。
幸亏框架是用maven进行管理,升级版本过程比较顺利,主要改写pom中的依赖:
hibernate pom dependency:
<dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>4.1.1.Final</version></dependency>
<properties> <spring.version>3.1.1.RELEASE</spring.version> </properties> .... <dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-expression</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-beans</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context-support</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-orm</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-oxm</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-aop</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>${spring.version}</version></dependency><repository> <id>springsource-repo</id> <name>springsource repository</name> <url>http://repo.springsource.org/release</url></repository><repository> <id>repository.jboss.org-public</id> <name>JBoss repository</name> <url>https://repository.jboss.org/nexus/content/groups/public</url> </repository>
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> <scope>provided</scope></dependency>
<bean id="sessionFactory" ref="dataSource"/> ... </bean> <bean id="transactionManager" ref="sessionFactory"/> </bean>
<tx:advice id="baseServiceAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="get*" read-only="true" propagation="REQUIRED"/><!--之前是NOT_SUPPORT--> <tx:method name="find*" read-only="true" propagation="REQUIRED"/><!--之前是NOT_SUPPORT--> <tx:method name="save*" propagation="REQUIRED"/> <tx:method name="update*" propagation="REQUIRED"/> <tx:method name="remove*" propagation="REQUIRED"/> <tx:method name="add*" propagation="REQUIRED"/> <!--默认其他方法都是REQUIRED--> <tx:method name="*"/> </tx:attributes> </tx:advice>
<filter> <filter-name>openSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class> </filter>