Below is the sample code snippet with spring transaction . My question :-Will same session be used for fetching entities at line1 and line2 ?
My understanding :- I believe yes and it will be ensured by spring transaction
@Transactional()
public void method1(
//fetch entity1 from dao with the help of entity manager//line 1
// fetch entity2 from dao with the help of entity manager//line 2
// now I fetch thru method entity.fetchLazyField()// line 3
)
Now if i remove @Transactional(). I believe session will be closed as soon as entity1 is fetched and separate session will be used for line2. Right ?
At line 3(once @Transactional is removed) , will I be able to fetch data or session is closed exception should be thrown ?
I am not pasting big xml configuration and complete dao code which just fetch the etity with entity manager. Transaction propagation attribute is Required
Will same session be used for fetching entities at line1 and line2 ?
yes you are right (assuming you are not using PersistenceContextType.EXTENDED)
Now if i remove @Transactional(). I believe session will be closed as soon as entity1 is fetched and separate session will be used for line2. Right ?