猿问

“立即更新”,Oracle,springframework,QuerySyntaxException

我正在使用实现从org.springframework.data.repository.CrudRepository和扩展的接口org.springframework.data.jpa.repository.JpaSpecificationExecutor


我有一个org.springframework.data.jpa.repository.Query带有参数的查询的问题org.springframework.data.repository.query.Param


我有这个查询..


@Query(value = " SELECT c FROM Ctype c WHERE c.code = :code"

        + " FOR UPDATE nowait ")

Ctype findOneByCodeNoWait(

        @Param("code") String code);

我有这个错误:


Caused by: java.lang.IllegalArgumentException: Validation failed for query for method public abstract org.company.persistence.entity.Ctype org.company.persist.repository.CtypeRepository.findOneByCodeNoWait(java.lang.String)!

Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: FOR near line 1, column 111 [ SELECT c FROM org.company.persistence.entity.Ctype c WHERE c.code = :code FOR UPDATE nowait ]

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: FOR near line 1, column 111 [ SELECT c FROM org.company.persistence.entity.Ctype c WHERE c.code = :code FOR UPDATE nowait ]\"}}"

我正在检查另一个帖子,但他们使用EntityManager...


这个怎么解决?


郎朗坤
浏览 190回答 1
1回答

holdtom

试试这个方法:@Lock(LockModeType.PESSIMISTIC_READ)&nbsp;@QueryHints(@QueryHint(name = "javax.persistence.lock.timeout",value = "0"))&nbsp;@Query(value = " SELECT c FROM Ctype c WHERE c.code = :code")我已经用我正在进行的项目和这段代码对此进行了测试:@Lock(LockModeType.PESSIMISTIC_READ)@QueryHints(@QueryHint(name = "javax.persistence.lock.timeout",value = "0"))@Query("select t from Event t left join fetch t.details ")List<Event> findAllWithDetails();`生成 sql 如下:SELECT event0_.event_id ...FROM&nbsp; &nbsp;EVENTS event0_&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;left outer join event_details details1_&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ON event0_.event_id = details1_.event_id&nbsp;FOR UPDATE NOWAIT
随时随地看视频慕课网APP

相关分类

Java
我要回答