我有一个 2 个实体 - Klient和DocAcc。为了访问我的数据,我使用 Spring Data。这是我的存储库:
public interface DocAccRepository extends CrudRepository<DocAcc, Long> {
@Query("select d from DocAcc d where d.sals = klient.sals")
List<DocAcc> findByKlient(Klient klient);
}
此代码不起作用。错误:
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Invalid path: 'klient.sals' [select d from vap.entity.DocAcc d where d.sals = klient.sals]
我的实体连接了不止一个字段。如何访问 Query 中的对象参数?
您可以在 @Query 中使用 SpEL 表达式
public interface DocAccRepository extends CrudRepository<DocAcc, Long> {
@Query("select d from DocAcc d where d.sals = :#{#klient.sals}")
List<DocAcc> findByKlient(@Param("klient") Klient klient);
}
更多信息:https : //spring.io/blog/2014/07/15/spel-support-in-spring-data-jpa-query-definitions
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句