在Spring存储库中查询

时间:2014-04-09 07:43:45

标签: spring hibernate

我的SQL是

SELECT formid 
  FROM (SELECT formid, COUNT(*) cc FROM formevalremarks
                 WHERE completed='Y' GROUP BY formid)
 WHERE (formid, cc) IN
                (SELECT formid, COUNT(*) dd FROM formevalremarks GROUP BY formid)

如何在Spring Repo ????

中的@Query中编写它

我试过..

@Query("select f.formId from (SELECT f.formId ,COUNT(*) f.cc FROM FormEvalRemarks f WHERE f.completed='Y' GROUP BY f.formId) where (f.formId ,f.cc ) in (SELECT f.formId ,COUNT(*) f.dd FROM FormEvalRemarks f GROUP BY f.formId)")
List<Long> complForms()
;

得到...... org.springframework.beans.factory.BeanCreationException

1 个答案:

答案 0 :(得分:0)

我早上有例外,正确的做法是。

@Query("select f.formId as formID  from 
         (SELECT f.formId ,COUNT(*)  f.cc  FROM FormEvalRemarks f WHERE f.completed='Y' GROUP BY f.formId) where (f.formId ,f.cc )  in (SELECT f.formId ,COUNT(*) f.dd  FROM FormEvalRemarks f GROUP BY f.formId)" , native=true)
   List<Long> methodToExecute();

如果不起作用,请尝试使用。

@NamedNativeQuery(name="MyQuery", query="select f.formId as formID  from (SELECT f.formId ,COUNT(*)  f.cc  FROM FormEvalRemarks f WHERE f.completed='Y' GROUP BY f.formId) where (f.formId ,f.cc )  in (SELECT f.formId ,COUNT(*) f.dd  FROM FormEvalRemarks f GROUP BY f.formId)", resultSetMapping = "MyMapper")

@SqlResultSetMapping(name="MyMapper",
    columns={
        @ColumnResult(name="formID")
    }
)

@Query(name="MyQuery" , native=true)
List<Object> methodToExecute();