title: Howto call Oracle function which returns a string using Hibernate/JPA?
body: <p>I want to call a Oracle function using JPA. I found <a href="https://stackoverflow.com/questions/14335939/how-to-call-oracle-function-or-procedure-using-hibernate-4-entitymanager-or-jp">this thread</a> on this topic.</p>
  
  <p>But my Oracle function only returns a string. Not the result for some kind of entity. I tried something like this:
  </p>
  
  <pre><code>@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") }
  )
  </code></pre>
  
  <p>When I call the query like this
  </p>
  
  <pre><code>Query query = em.createNamedQuery("myFuncCall", String.class).setParameter("id", "42");
          String res = (String) query.getSingleResult();
  </code></pre>
  
  <p>I get
  </p>
  
  <pre><code>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)
  </code></pre>
  
  <p>Any ideas?</p>