初探hibernate和spring集成得事务控制原理,欢迎交流。

For contrasaction by Spring,commonly,we take the tier of service for transaction control,but when we integrate hibernate to spring, Spring use Session gothrough the whole process, that is to say when the thread going to the method of service tier-- if the prefix of method is defined in the strategy in xml ,the transaction will effect, whatever you did in this operation to database,it will in one transaction in common,during this process, if happen exception, it will rollback. this is as to useaual. But for Session of hibernate integerated with Spring,during the current transaction, if you perform batch job since the BO has complicated realationship like one-to-many,or many-to-one, some times  it will happen a error as "found shared references to a collection".If you think more for detail of transaction by Spring integreted Hibernate, you will get why happen.
if you process like this,
1.get data list from one database,update some,and then update it to DB,or get the data and then create new record which data from pre data list.
to avoid this , you can do in two ways:
a. make simple for data structure in bo and get data by writing sql or hql.if you get data in this way, when create or update database, you can do anyway if you like as no  need to to warry about anything in service tier and no need to make the thread leave this tier.
b.for above case,if you don't remove the complicated data structure and realationship between BO,when creating or updating,due to the session have  the reference of BO, so if you want to create or update as usual,hibernate will happen error as above, for this, we can think a another way, which  is getting data before calling method of serivce tier. and then parse the data to serivce tier as once your thread leave service tier, sesion will flush automaiclly. hahahahaha....
one commont:the much you use spring integerated hibernate, the more intresting things you will see. 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值