2012-02-15 2 views
0

現在、私はクライアント側のパーサー用のDocumentサービスを用意して、ユーザーが許可されたドキュメントを表示、編集、管理できるようにしています。 Documentprivilegesには、ドキュメントモデルに対して@onetomanyの関係があります。私は、ドキュメントjpa(hibernate)クエリの結果リストをHashMapとして取得するには?

私もオーバーライドされたメソッドを介してのHashMap(DOCIDと権限を)返したい
public String getDocumentPrivilege(Long documentId); 
    ...... 

ことにより、単一の権限を取得する追加されました。これまでのところ私が行っている:

@Override 
    public HashMap<Long, String> getDocumentPrivilege(List<Long> documentIds) 
    { 
     Query q = null; 
     if (documentIds != null && documentIds.size()>0) { 
      q = em.createQuery("select new map(d.document_id as id, d.privilege as privilege) from DocumentPrivileges d" 
        + " where d.document_id IN ?1"); 
      q.setParameter(1, documentIds); 
      @SuppressWarnings("unchecked") 
      HashMap<Long, String> results = (HashMap<Long, String>) q.getResultList(); 
      if(results != null && results.size()>0) 
      return results; 
     } 
     return null; 
    } 

しかし、私はエラーの下に取得しています:私は他の例をチェックした

Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: : near line 1, column 140 [select new map(d.document_id as id, d.privilege as privilege) from xxx.xxxx.xxxx.xxxmodel.DocumentPrivileges d where d.document_id IN :docs] 
    at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54) 
    at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47) 
    at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82) 
    at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:284) 
    at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:182) 
    at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136) 
    at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101) 
    at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80) 
    at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:98) 
    at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156) 
    at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135) 
    at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1760) 
    at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:268) 
    ... 136 more 

それは非常に類似していました。間違ったやり方をしていますか?

答えて

0

マップがmap<column, value>に事前に定義されていないmap<column1value, column2value>あなたがあなたのクエリで、HQLのオペレータ「IN」と一緒に使用される文書IDのリストを設定するには、setParameterListを使用する必要がありますresultlist

0

からマップを構築する必要が。

関連する問題