Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
org.hibernate.hql.internal.ast.QuerySyntaxException:意外标记:在第1行第17列附近不同_Hibernate_Spring Data Jpa_Jpql - Fatal编程技术网

org.hibernate.hql.internal.ast.QuerySyntaxException:意外标记:在第1行第17列附近不同

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

我正在尝试使用Query方法在存储库中执行以下查询。我需要唯一的Slocation,结果应该是
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();