我想使用JPA調用Oracle函數。我在這個主題上找到了this thread。如何調用使用Hibernate/JPA返回字符串的Oracle函數?
但是我的Oracle函數只返回一個字符串。不是某種實體的結果。我想是這樣的:
@NamedNativeQuery(name = "myFuncCall",
resultSetMapping = "myResultSetMapping",
query = "{ ? = call schema.mypkg.somefunc(:id) }",
hints = { @javax.persistence.QueryHint(name = "org.hibernate.callable", value = "true") }
)
@SqlResultSetMapping(name = "myResultSetMapping",
columns = { @ColumnResult(name="somename") }
)
當我打電話這樣
Query query = em.createNamedQuery("myFuncCall", String.class).setParameter("id", "42");
String res = (String) query.getSingleResult();
查詢我得到
Hibernate: { ? = call schema.somefunc(?) }
18:21:11.222 [main] WARN o.h.util.JDBCExceptionReporter - SQL Error: 6550, SQLState: 65000
18:21:11.222 [main] ERROR o.h.util.JDBCExceptionReporter - ORA-06550: Row 1, Column 13:
PLS-00382: This expression has the wrong type
ORA-06550: Row 1, Column 7:
PL/SQL: Statement ignored
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1389)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1317)
at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:307)
任何想法?
你有沒有發現任何有用的東西,我也一起砍了其他東西 – NimChimpsky
不,它仍然像下面一樣,不幸的是。 – Stefan