org.hibernate.hql.internal.ast.QuerySyntaxException:意外标记:第 1 行第 17 列附近不同
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: distinct near line 1, column 17
我正在尝试使用查询方法在存储库中执行以下查询。我想要唯一的位置,结果应该是 JSON
格式(键,值)
这是我的代码
@Repository
public interface AccountRepository extends JpaRepository<Account, Integer>, QueryDslPredicateExecutor<Account> {
// Load location
@Query("select new map (distinct(a.slocation) as slocation) from Account a where a.slocation !=null")
Set<Account> findSlocation();
错误
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: distinct near line 1, column 17 [select new map (distinct(a.slocation) as slocation) from com.spacestudy.model.Account a where a.slocation !=null]
谁能告诉我如何解决这个错误?
你可以使用这个:
@Query("select new map (a.slocation) from Account a where a.slocation !=null group by slocation")
我得到了另一种解决方案,我删除了 distinct 并添加了 Set
而不是 List
@Query("select new map (a.slocation as slocation) from AccountModel a where a.slocation !=null")
Set<AccountModel> findBySlocation();
我正在尝试使用查询方法在存储库中执行以下查询。我想要唯一的位置,结果应该是 JSON
格式(键,值)
这是我的代码
@Repository
public interface AccountRepository extends JpaRepository<Account, Integer>, QueryDslPredicateExecutor<Account> {
// Load location
@Query("select new map (distinct(a.slocation) as slocation) from Account a where a.slocation !=null")
Set<Account> findSlocation();
错误
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: distinct near line 1, column 17 [select new map (distinct(a.slocation) as slocation) from com.spacestudy.model.Account a where a.slocation !=null]
谁能告诉我如何解决这个错误?
你可以使用这个:
@Query("select new map (a.slocation) from Account a where a.slocation !=null group by slocation")
我得到了另一种解决方案,我删除了 distinct 并添加了 Set
而不是 List
@Query("select new map (a.slocation as slocation) from AccountModel a where a.slocation !=null")
Set<AccountModel> findBySlocation();