java - JPA 2.1 - Not able to call Oracle function -
i not able call oracle function through jpa 2.1. same function works fine jdbc callablestatement.
i have below definition in entity class.
@namednativequery(name = "getallairlinesnq", query = "{? = call pkg_airlines.get_airlines()}", resultclass = airline.class, hints = { @queryhint(name = "org.hibernate.callable", value = "true") })
and in dao call oracle function this,
entitymanager entitymanager = entitymanagerfactory.createentitymanager(); query query = entitymanager.createnativequery("getallairlinesnq"); list<airline> airlines = query.getresultlist(); return airlines;
oracle function:
function get_airlines return sys_refcursor o_cursor sys_refcursor; begin open o_cursor select a1.id id, a1.name name, a1.alias alias, a1.iata iata, a1.icao icao, a1.call_sign call_sign, a1.country_code country_code airlines a1; return o_cursor; end get_airlines;
i error,
javax.persistence.persistenceexception: org.hibernate.exception.sqlgrammarexception: not extract resultset @ org.hibernate.jpa.spi.abstractentitymanagerimpl.convert(abstractentitymanagerimpl.java:1763) @ org.hibernate.jpa.spi.abstractentitymanagerimpl.convert(abstractentitymanagerimpl.java:1677) @ org.hibernate.jpa.internal.queryimpl.getresultlist(queryimpl.java:458) @ com.jai.entity.dao.airlinedao.getallairlinesnqfn(airlinedao.java:141) @ com.jai.entity.dao.airlinedaotest.testgetairlinesfn(airlinedaotest.java:117) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ org.junit.runners.model.frameworkmethod$1.runreflectivecall(frameworkmethod.java:47) @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:12) @ org.junit.runners.model.frameworkmethod.invokeexplosively(frameworkmethod.java:44) @ org.junit.internal.runners.statements.invokemethod.evaluate(invokemethod.java:17) @ org.junit.internal.runners.statements.runbefores.evaluate(runbefores.java:26) @ org.junit.internal.runners.statements.runafters.evaluate(runafters.java:27) @ org.junit.rules.expectedexception$expectedexceptionstatement.evaluate(expectedexception.java:168) @ org.junit.rules.runrules.evaluate(runrules.java:20) @ org.junit.runners.parentrunner.runleaf(parentrunner.java:271) @ org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:70) @ org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:50) @ org.junit.runners.parentrunner$3.run(parentrunner.java:238) @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:63) @ org.junit.runners.parentrunner.runchildren(parentrunner.java:236) @ org.junit.runners.parentrunner.access$000(parentrunner.java:53) @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:229) @ org.junit.internal.runners.statements.runbefores.evaluate(runbefores.java:26) @ org.junit.internal.runners.statements.runafters.evaluate(runafters.java:27) @ org.junit.runners.parentrunner.run(parentrunner.java:309) @ org.eclipse.jdt.internal.junit4.runner.junit4testreference.run(junit4testreference.java:50) @ org.eclipse.jdt.internal.junit.runner.testexecution.run(testexecution.java:38) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:459) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:675) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.run(remotetestrunner.java:382) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.main(remotetestrunner.java:192) caused by: org.hibernate.exception.sqlgrammarexception: not extract resultset @ org.hibernate.exception.internal.sqlexceptiontypedelegate.convert(sqlexceptiontypedelegate.java:80) @ org.hibernate.exception.internal.standardsqlexceptionconverter.convert(standardsqlexceptionconverter.java:49) @ org.hibernate.engine.jdbc.spi.sqlexceptionhelper.convert(sqlexceptionhelper.java:126) @ org.hibernate.engine.jdbc.spi.sqlexceptionhelper.convert(sqlexceptionhelper.java:112) @ org.hibernate.engine.jdbc.internal.resultsetreturnimpl.extract(resultsetreturnimpl.java:91) @ org.hibernate.loader.loader.getresultset(loader.java:2066) @ org.hibernate.loader.loader.executequerystatement(loader.java:1863) @ org.hibernate.loader.loader.executequerystatement(loader.java:1839) @ org.hibernate.loader.loader.doquery(loader.java:910) @ org.hibernate.loader.loader.doqueryandinitializenonlazycollections(loader.java:355) @ org.hibernate.loader.loader.dolist(loader.java:2554) @ org.hibernate.loader.loader.dolist(loader.java:2540) @ org.hibernate.loader.loader.listignorequerycache(loader.java:2370) @ org.hibernate.loader.loader.list(loader.java:2365) @ org.hibernate.loader.custom.customloader.list(customloader.java:353) @ org.hibernate.internal.sessionimpl.listcustomquery(sessionimpl.java:1909) @ org.hibernate.internal.abstractsessionimpl.list(abstractsessionimpl.java:311) @ org.hibernate.internal.sqlqueryimpl.list(sqlqueryimpl.java:141) @ org.hibernate.jpa.internal.queryimpl.list(queryimpl.java:573) @ org.hibernate.jpa.internal.queryimpl.getresultlist(queryimpl.java:449) ... 31 more caused by: java.sql.sqlsyntaxerrorexception: ora-00900: invalid sql statement @ oracle.jdbc.driver.t4cttioer.processerror(t4cttioer.java:450) @ oracle.jdbc.driver.t4cttioer.processerror(t4cttioer.java:399) @ oracle.jdbc.driver.t4c8oall.processerror(t4c8oall.java:1017) @ oracle.jdbc.driver.t4cttifun.receive(t4cttifun.java:655) @ oracle.jdbc.driver.t4cttifun.dorpc(t4cttifun.java:249) @ oracle.jdbc.driver.t4c8oall.dooall(t4c8oall.java:566) @ oracle.jdbc.driver.t4cpreparedstatement.dooall8(t4cpreparedstatement.java:215) @ oracle.jdbc.driver.t4cpreparedstatement.dooall8(t4cpreparedstatement.java:58) @ oracle.jdbc.driver.t4cpreparedstatement.executeforrows(t4cpreparedstatement.java:943) @ oracle.jdbc.driver.oraclestatement.doexecutewithtimeout(oraclestatement.java:1075) @ oracle.jdbc.driver.oraclepreparedstatement.executeinternal(oraclepreparedstatement.java:3820) @ oracle.jdbc.driver.oraclepreparedstatement.executequery(oraclepreparedstatement.java:3867) @ oracle.jdbc.driver.oraclepreparedstatementwrapper.executequery(oraclepreparedstatementwrapper.java:1502) @ org.hibernate.engine.jdbc.internal.resultsetreturnimpl.extract(resultsetreturnimpl.java:82) ... 46 more
you using wrong method creating named query - should use entitymanager.createnamedquery()
, not entitymanager.createnativequery()
.
Comments
Post a Comment