0

假设我们有一个这样的查询方法:

@Query("select p from Parent p left join fetch p.children c where p.id = :id")
Parent findWithChildrenById(Long id);

可以使用以下代码重写相同的内容@EntityGraph

@EntityGraph(attributePaths = "children")
Parent findWithChildrenById(Long id);

如果我们想为第一种方法添加一个悲观锁,我们会这样做(该方法取自这个答案:https ://stackoverflow.com/a/63842764/5572007 ):

@Query("select p from Parent p left join fetch p.children c where p.id = :id")
@Lock(LockModeType.PESSIMISTIC_WRITE)
@QueryHints(
    @QueryHint(name = "org.hibernate.lockMode.c", value = "NONE")
)
Parent findWithChildrenPessimisticById(Long id);

问题是:是否可以对第二个查询(带有实体图的查询)做同样的事情?在这种情况下如何指定提示值?

我尝试了“org.hibernate.lockMode.children”甚至“org.hibernate.lockMode.children1_”(后者来自生成的Hibernate查询)。两个提示都不起作用。

4

0 回答 0