title: Execute database function with JPA
body: <p>To call an Oracle database function I'd simply write</p>
  
  <pre><code>final Query query = entityManager.createNativeQuery(
      "select myfunction(?) from dual"
  );
  query.setParameter(1, "value");
  Object rv = query.getSingleResult();
  </code></pre>
  
  <p>This works as long as the called function doesn't execute any dml operations.
  Otherwise I'd have to execute something like</p>
  
  <pre><code>    {? = call myfunction(?)}
  </code></pre>
  
  <p>Unfortunately I can't register any OUT parameters, so I can't get this statement to work.
  How can I achieve that without using plain JDBC?</p>
  
  <hr>
  
  <p><strong>Edit:</strong></p>
  
  <p>The question was misleading. I want to fetch the result of a function (not a stored procedure) in an Oracle database. There are no OUT parameters. The function could look like this:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION myfunction(value IN VARCHAR2)
  RETURN VARCHAR2
  IS
  BEGIN
      UPDATE foo SET bar = 'foobar'
      WHERE id = 1;
  
      RETURN 'test';
  END myfunction;
  </code></pre>
  
  <p>The answer to <a href="https://stackoverflow.com/questions/5688152/calling-an-oracle-function-from-jpa">Calling an oracle function from JPA</a> does not solve my problem since there are dml changes inside my function. I get an error:</p>
  
  <blockquote>
    <p>cannot perform a DML operation inside a query</p>
  </blockquote>