# NumericBooleanType hibernate type cannot bind value in StoredProcedureQuery

**URL:** <https://discourse.hibernate.org/t/numericbooleantype-hibernate-type-cannot-bind-value-in-storedprocedurequery/882>\
**Category:** Hibernate ORM\
**Created:** [June 4, 2018, 8:26am UTC](https://discourse.hibernate.org/t/numericbooleantype-hibernate-type-cannot-bind-value-in-storedprocedurequery/882 "2018-06-04T08:26:29Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![roland.kurucz](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@roland.kurucz](https://discourse.hibernate.org/u/roland.kurucz)\
**Post date:** [June 4, 2018, 8:26am UTC](https://discourse.hibernate.org/t/numericbooleantype-hibernate-type-cannot-bind-value-in-storedprocedurequery/882/1 "2018-06-04T08:26:29Z")

</div>

Hi all,

I tried to call a procedure with **Hibernate ORM 5.3.0.Final** , then I got an IllegalArgumentException.  
Example code:

```auto
inTransaction(
				session -> {
					final StoredProcedureQuery procedureQuery = session.createStoredProcedureQuery( "test" );

					procedureQuery.registerStoredProcedureParameter(1, NumericBooleanType.class, ParameterMode.IN);
					procedureQuery.setParameter( 1, false );
				}
		);

```

Exception:

```auto
**java.lang.IllegalArgumentException: Bind value [false] was not of specified type [class org.hibernate.type.NumericBooleanType**
	at org.hibernate.procedure.internal.ParameterBindImpl.internalSetValue(ParameterBindImpl.java:83)
	at org.hibernate.procedure.internal.ParameterBindImpl.setBindValue(ParameterBindImpl.java:64)
	at org.hibernate.procedure.internal.ProcedureCallImpl.setParameter(ProcedureCallImpl.java:818)
	at org.hibernate.procedure.internal.ProcedureCallImpl.setParameter(ProcedureCallImpl.java:70)

```

Could you help me for this issue?

Best Regards  
Roland

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [June 4, 2018, 8:46am UTC](https://discourse.hibernate.org/t/numericbooleantype-hibernate-type-cannot-bind-value-in-storedprocedurequery/882/2 "2018-06-04T08:46:15Z")

</div>

Change this:

`procedureQuery.registerStoredProcedureParameter(1, NumericBooleanType.class, ParameterMode.IN);`

to this:

`procedureQuery.registerStoredProcedureParameter(1, Boolean.class, ParameterMode.IN);`

The type parameter is the Java Type of the parameter and has nothing to do with Hibernate Types.

---

<div class="post-metadata">

**Author:** ![roland.kurucz](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@roland.kurucz](https://discourse.hibernate.org/u/roland.kurucz)\
**Post date:** [June 4, 2018, 9:43am UTC](https://discourse.hibernate.org/t/numericbooleantype-hibernate-type-cannot-bind-value-in-storedprocedurequery/882/3 "2018-06-04T09:43:21Z")

</div>

This NumericBooleanType works in the previous Hibernate version 5.2.  
What about the YesNoType? The result of it is the same exception.  
How can I use my own implementations of UserType?

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [June 4, 2018, 9:55am UTC](https://discourse.hibernate.org/t/numericbooleantype-hibernate-type-cannot-bind-value-in-storedprocedurequery/882/4 "2018-06-04T09:55:15Z")

</div>

This is how the type is passed on:

```auto
public <T> ParameterRegistration<T> registerParameter(int position, Class<T> type, ParameterMode mode) {
	final ProcedureParameterImpl procedureParameter = new ProcedureParameterImpl(
			this,
			position,
			mode,
			type,
			getSession().getFactory().getTypeResolver().heuristicType( type.getName() ),
			globalParameterPassNullsSetting
	);

	registerParameter( procedureParameter );
	return procedureParameter;
}

```

Notice that you have both the `type` and the `hibernateType`. Theoretically, you could use a custom Type as well. Just try it and see where it breaks.

Better build up a test case as it’s going to be easier to implement a fix if it turns out to be an issue in hibernate-core.

---

<div class="post-metadata">

**Author:** ![roland.kurucz](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@roland.kurucz](https://discourse.hibernate.org/u/roland.kurucz)\
**Post date:** [June 4, 2018, 11:15am UTC](https://discourse.hibernate.org/t/numericbooleantype-hibernate-type-cannot-bind-value-in-storedprocedurequery/882/5 "2018-06-04T11:15:50Z")

</div>

In my opinion, the backward compatibility is most important.  
Please give me a solution, how can I use the YesNoType in a StoredProcedureQuery.

I have debugged the codes in hibernate-core. The implementation of ParameterRegistration was changed.  
The implementations of ParameterRegistration in Hibenate 5.2:  
NamedParameterRegistration:

```auto
	@Override
	@SuppressWarnings("unchecked")
	public <T> ParameterRegistration<T> registerParameter(String name, Class<T> type, ParameterMode mode) {
		final NamedParameterRegistration parameterRegistration = new NamedParameterRegistration( this, name, mode, type, globalParameterPassNullsSetting );
		registerParameter( parameterRegistration );
		return parameterRegistration;
	}

```

PositionalParameterRegistration:

```auto
	@Override
	@SuppressWarnings("unchecked")
	public <T> ParameterRegistration<T> registerParameter(int position, Class<T> type, ParameterMode mode) {

		final PositionalParameterRegistration parameterRegistration =
				new PositionalParameterRegistration( this, position, mode, type, globalParameterPassNullsSetting );
		registerParameter( parameterRegistration );
		return parameterRegistration;
	}

```

The implementation was changed at this commit: [https://github.com/hibernate/hibernate-orm/commit/6ba328e7a03d2faaf648e85310e903f11211cbd8](https://github.com/hibernate/hibernate-orm/commit/6ba328e7a03d2faaf648e85310e903f11211cbd8)

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [June 4, 2018, 11:30am UTC](https://discourse.hibernate.org/t/numericbooleantype-hibernate-type-cannot-bind-value-in-storedprocedurequery/882/6 "2018-06-04T11:30:35Z")

</div>

> Better build up a test case as it’s going to be easier to implement a fix if it turns out to be an issue in hibernate-core.

---

<div class="post-metadata">

**Author:** ![roland.kurucz](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@roland.kurucz](https://discourse.hibernate.org/u/roland.kurucz)\
**Post date:** [June 4, 2018, 3:05pm UTC](https://discourse.hibernate.org/t/numericbooleantype-hibernate-type-cannot-bind-value-in-storedprocedurequery/882/7 "2018-06-04T15:05:38Z")

</div>

Please perform these tests with Hibernate 5.2 and 5.3.

```auto
package com.example;

import org.hibernate.Session;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.hibernate.type.NumericBooleanType;
import org.hibernate.type.YesNoType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import javax.persistence.ParameterMode;

@RequiresDialect(H2Dialect.class)
public class StoredProcedureApiTest extends BaseNonConfigCoreFunctionalTestCase {

    private Session session;

    @Before
    public void setUp() {
        session = openSession();
    }

    @After
    public void tearDown() {
        session.close();
    }

    @Test
    public void testNumericBooleanTypeInParameter() {
        session.createStoredProcedureQuery("test")
                .registerStoredProcedureParameter(1, NumericBooleanType.class, ParameterMode.IN)
                .registerStoredProcedureParameter(2, String.class, ParameterMode.OUT)
                .setParameter(1, false);
    }

    @Test
    public void testYesNoTypeInParameter() {
        session.createStoredProcedureQuery("test")
                .registerStoredProcedureParameter(1, YesNoType.class, ParameterMode.IN)
                .registerStoredProcedureParameter(2, String.class, ParameterMode.OUT)
                .setParameter(1, false);
    }

}

```

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [June 4, 2018, 3:13pm UTC](https://discourse.hibernate.org/t/numericbooleantype-hibernate-type-cannot-bind-value-in-storedprocedurequery/882/8 "2018-06-04T15:13:23Z")

</div>

Great. Please send it as a Pull Request as explained in [this article](http://in.relation.to/2018/06/04/best-way-write-hibernate-orm-issue-test-case/).

---

<div class="post-metadata">

**Author:** ![roland.kurucz](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@roland.kurucz](https://discourse.hibernate.org/u/roland.kurucz)\
**Post date:** [June 6, 2018, 1:22pm UTC](https://discourse.hibernate.org/t/numericbooleantype-hibernate-type-cannot-bind-value-in-storedprocedurequery/882/9 "2018-06-06T13:22:00Z")

</div>

Thanks the information.

I have created an issue about this problem in the Hibernate Issue System

[https://hibernate.atlassian.net/browse/HHH-12661](https://hibernate.atlassian.net/browse/HHH-12661)

The test cases are coming soon.

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [June 6, 2018, 1:24pm UTC](https://discourse.hibernate.org/t/numericbooleantype-hibernate-type-cannot-bind-value-in-storedprocedurequery/882/10 "2018-06-06T13:24:31Z")

</div>

Thanks. I can do the test as I wanted to have one for Oracle which does not support a true boolean type anyway.

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [June 6, 2018, 3:01pm UTC](https://discourse.hibernate.org/t/numericbooleantype-hibernate-type-cannot-bind-value-in-storedprocedurequery/882/11 "2018-06-06T15:01:41Z")

</div>

I submitted a [Pull Request](https://github.com/hibernate/hibernate-orm/pull/2326). If it’s approved, we can have it in the next 5.3.x release.

---

<div class="post-metadata">

**Author:** ![roland.kurucz](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@roland.kurucz](https://discourse.hibernate.org/u/roland.kurucz)\
**Post date:** [June 6, 2018, 7:09pm UTC](https://discourse.hibernate.org/t/numericbooleantype-hibernate-type-cannot-bind-value-in-storedprocedurequery/882/12 "2018-06-06T19:09:04Z")

</div>

Thank you very much.

I have added a Pull Request with some tests: [https://github.com/hibernate/hibernate-orm/pull/2327](https://github.com/hibernate/hibernate-orm/pull/2327)

I hope It is not problem.

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [June 6, 2018, 7:28pm UTC](https://discourse.hibernate.org/t/numericbooleantype-hibernate-type-cannot-bind-value-in-storedprocedurequery/882/13 "2018-06-06T19:28:19Z")

</div>

Thanks. I’ll review it tomorrow.
