org.hibernate.hql.internal.ast.QuerySyntaxException:意外标记:在第1行第17列附近不同
我正在尝试使用Query方法在存储库中执行以下查询。我需要唯一的Slocation,结果应该是org.hibernate.hql.internal.ast.QuerySyntaxException:意外标记:在第1行第17列附近不同,hibernate,spring-data-jpa,jpql,Hibernate,Spring Data Jpa,Jpql,我正在尝试使用Query方法在存储库中执行以下查询。我需要唯一的Slocation,结果应该是JSON格式(key,value) 这是我的代码 @Repository public interface AccountRepository extends JpaRepository<Account, Integer>, QueryDslPredicateExecutor<Account> { // Load location @Query("select
JSON
格式(key,value)
这是我的代码
@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();
有人能告诉我如何解决这个错误吗?您可以使用这个:
@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();
@Query(“从AccountModel a中选择新映射(a.slocation作为slocation),其中a.slocation!=null”)
设置findBySlocation();
我得到了预期的结果。
@Query("select new map (a.slocation as slocation) from AccountModel a where a.slocation !=null")
Set<AccountModel> findBySlocation();