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.
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.