title: Is it possible to pass a null parameter to a stored procedure in Java JPA 2.1?
body: <p>Using the new JPA 2.1 <a href="http://docs.oracle.com/javaee/7/api/javax/persistence/EntityManager.html#createStoredProcedureQuery%28java.lang.String%29">stored procedure</a> call, is there any way to pass a null parameter?</p>
  
  <p>Here is an example usage:</p>
  
  <pre><code>StoredProcedureQuery storedProcedure = em.createStoredProcedureQuery("get_item", Item.class);
  storedProcedure.registerStoredProcedureParameter(0, String.class, ParameterMode.IN);
  storedProcedure.registerStoredProcedureParameter(1, String.class, ParameterMode.IN);
  storedProcedure.registerStoredProcedureParameter(2, Timestamp.class, ParameterMode.IN);
  
  storedProcedure.setParameter(0, a);
  storedProcedure.setParameter(1, b);
  storedProcedure.setParameter(2, c);
  
  storedProcedure.execute();
  </code></pre>
  
  <p>This works when all parameters are given, but when <code>c</code> is <code>null</code> it will fail with an error from the (PostgreSQL) JDBC driver.</p>
  
  <pre><code>Caused by: org.postgresql.util.PSQLException: No value specified for parameter 2
  at org.postgresql.core.v3.SimpleParameterList.checkAllParametersSet(SimpleParameterList.java:216) [postgresql-9.3-1101.jdbc41.jar:]
      at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:244) [postgresql-9.3-1101.jdbc41.jar:]
      at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:559) [postgresql-9.3-1101.jdbc41.jar:]
      at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417) [postgresql-9.3-1101.jdbc41.jar:]
      at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:410) [postgresql-9.3-1101.jdbc41.jar:]
      at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.execute(WrappedPreparedStatement.java:404)
      at org.hibernate.result.internal.OutputsImpl.&lt;init&gt;(OutputsImpl.java:69) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
      ... 244 more
  </code></pre>
  
  <p>I have also considered using my own class for passing the parameters, eg:</p>
  
  <pre><code>storedProcedure.registerStoredProcedureParameter(0, InputParameters.class, ParameterMode.IN);
  storedProcedure.setParameter(0, inputParameters);
  </code></pre>
  
  <p>This fails with:</p>
  
  <pre><code>Caused by: java.lang.IllegalArgumentException: Type cannot be null
  </code></pre>
  
  <p>I guess because it needs a type that can be mapped to an SQL type.</p>
  
  <p>Is there a way to pass a null parameter?</p>