存储过程代码:CREATEPROCEDUREgetallid()BEGINselectsum(id)fromuser;ENDJavaDAO层代码:@OverridepublicintfindAllId(){Queryquery=this.entityManager.createQuery("callgetallid()");inti=(int)query.getSingleResult();returni;}报错原因:org.hibernate.hql.internal.ast.QuerySyntaxException:unexpectedtoken:callnearline1,column1[callgetallid()]atorg.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:74)~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]atorg.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:91)~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]atorg.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:291)~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]atorg.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:186)~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]atorg.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:141)~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]atorg.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:115)~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]atorg.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:77)~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]atorg.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:153)~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]atorg.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:553)~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]atorg.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:662)~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]atorg.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:23)~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)~[na:1.8.0_144]atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)~[na:1.8.0_144]atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)~[na:1.8.0_144]atjava.lang.reflect.Method.invoke(Method.java:498)~[na:1.8.0_144]
2 回答
慕田峪7331174
TA贡献1828条经验 获得超13个赞
经过查询资料,使用createNativeQuery()方法是可行的。@OverridepublicIntegerfindAllId(){Queryquery=this.entityManager.createNativeQuery("callgetallid()");inti=Integer.parseInt(query.getSingleResult().toString());returni;}
添加回答
举报
0/150
提交
取消