spring3.0.5与hibernate3.6的集成初步

spring3.0.5对jpa2.0开始了支持.但jpa2.0的规范在web容器(tomcat)里,一直有几个地方挺头疼.就是EntityManager的关闭,事务提交,命名空间的问题.
如果EntityManager是受容器托管的,我们就不必去理会关闭的问题,这个是spring最吸引人的地方。让我们使用JPA感觉像在EJB3容器里一样的方便.而需要注意的地方是spring3.0.5支持的是JPA2.0的规范,这里我使用了hibernate3.6.只有版本匹配才能正常运行。昨天笔者用spring2.5.6与hibernate3.6(JPA)部分集成,始终没有成功.改用3.0.5成功.
hibernate3.6里的JPA,即使配置了<property name="hibernate.connection.autocommit" value="true" />,事务也不会自动提交,所以我们只要遇到更新或者删除等操作的时候,必须要begin和commit.所以只有通过spring的事务来处理这个事情.
最后一个是命名空间的问题,也就是头文件<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
如果编写不正确,不光是自动提示的问题,tomcat启动的时候会报异常,导致项目无法运行.
最后,我过段时间,会写个详细的文档,来展示hiberate3.6(JPA部分)与spring3.0.5的集成.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值