无需事务提取数据 [英] Fetching data without transaction

查看:106
本文介绍了无需事务提取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是带有spring事务的示例代码片段。我的问题: - 会使用相同的会话来获取第1行和第2行的实体吗?



我的理解: - 我相信是的,它将通过春季交易得到保证

  @Transactional()
public void method1(
//在实体管理器的帮助下从dao获取entity1 //第1行

//从dao获取entity2在实体管理器的帮助下//第2行

//现在我通过方法entity.fetchLazyField()//第3行

现在,如果我删除 @Transactional()。我相信只要entity1被提取,session就会被关闭,单独的session将被用于line2。在第3行(一旦 @Transactional 被删除),我将能够获取数据或会话应该抛出异常关闭吗?



我没有粘贴大的xml配置和完整的dao代码,它们只是通过实体管理器获取相应的属性。事务传播属性为必需

解决方案


将同一会话用于获取第1行和第2行的实体?


是的,您是对的(假设您 strong>使用 PersistenceContextType.EXTENDED


现在,如果我删除@Transactional()。我相信session1将被关闭为
,因为entity1被提取,单独的会话将被用于
line2。对吗?


我不这么认为,但请检查这个


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 ?

I don't think so, but check this and this.

这篇关于无需事务提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆