Passing null for a stored procedure parameter in Hibernate

Solution Verified - Updated -

Issue

  • The Hibernate 5.0 User Guide (section 22.7) documents the property hibernate.proc.param_null_passing which may be used to instruct Hibernate to pass null to the database when a null value is supplied by application code for a stored procedure parameter.
  • When hibernate.proc.param_null_passing is set to true and a JPA 2.1 StoredProcedureQuery.setParameter(String, Object) method is used to pass a null value, a database exception (similar to the one below) is raised indicating that the null was not passed to the database:

    java.sql.SQLException: No value specified for parameter 1
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1086)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
        at com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2594)
        at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2569)
        at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2493)
        at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1316)
        at com.mysql.jdbc.CallableStatement.execute(CallableStatement.java:920)
        at org.hibernate.result.internal.OutputsImpl.<init>(OutputsImpl.java:52)
    
    

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP) 7
  • Hibernate 5.0

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.