gpt4 book ai didi

java - 无事务获取数据

转载 作者:行者123 更新时间:2023-11-30 10:32:12 25 4
gpt4 key购买 nike

下面是带有 spring transaction 的示例代码片段。我的问题:- 同一 session 是否会用于在 line1 和 line2 处获取实体?

我的理解:- 我相信是的,这将通过 Spring 交易得到保证

@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
)

现在如果我删除 @Transactional()。我相信 session 将在获取 entity1 后立即关闭,并且单独的 session 将用于 line2。对吧?

在第 3 行(一旦 @Transactional 被删除),我是否能够获取数据或 session 关闭异常应该被抛出?

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

最佳答案

Will same session be used for fetching entities at line1 and line2 ?

是的,你是对的(假设你使用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 ?

我不这么认为,但请查看 thisthis .

关于java - 无事务获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42831749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com