java.lang.IllegalArgumentException: Type cannot be null

Hibernate JIRA | Gail Badner | 11 months ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    There is nothing in the API that prevents an embeddable parameter to be mapped for a stored procedure. For example, with Address is an embeddable: {{ @NamedStoredProcedureQuery( name = "User.findAddressById", resultClasses = User.class, procedureName = "PROC", parameters = { @StoredProcedureParameter(mode = ParameterMode.IN, name = "ID_PARAM", type = Integer.class), @StoredProcedureParameter(mode = ParameterMode.OUT, name = "ADDRESS_PARAM", type = Address.class) } ) }} When Hibernate tries to create the stored procedure, the following exception is thrown: {{ java.lang.IllegalArgumentException: Type cannot be null at org.hibernate.procedure.internal.AbstractParameterRegistrationImpl.setHibernateType(AbstractParameterRegistrationImpl.java:187) at org.hibernate.procedure.internal.AbstractParameterRegistrationImpl.<init>(AbstractParameterRegistrationImpl.java:124) at org.hibernate.procedure.internal.AbstractParameterRegistrationImpl.<init>(AbstractParameterRegistrationImpl.java:97) at org.hibernate.procedure.internal.NamedParameterRegistration.<init>(NamedParameterRegistration.java:35) at org.hibernate.procedure.internal.ProcedureCallImpl.<init>(ProcedureCallImpl.java:235) at org.hibernate.procedure.internal.ProcedureCallMementoImpl.makeProcedureCall(ProcedureCallMementoImpl.java:65) at org.hibernate.internal.SessionImpl.createNamedStoredProcedureQuery(SessionImpl.java:3636) at org.hibernate.jpa.test.procedure.StoreProcedureOutParameterByNameTest.testNamedBasicAndEmbeddableOutParameters(StoreProcedureOutParameterByNameTest.java:127) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.hibernate.testing.junit4.ExtendedFrameworkMethod.invokeExplosively(ExtendedFrameworkMethod.java:45) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:74) }} The Hibernate type for the embeddable is null because the ParameterMemento constructor passes the value returned by {{sessionFactory.getTypeResolver().heuristicType( type.getName() )}}, which returns {{null}}. In addition the following needs to be resolved to support this improvement: * for a named embeddable parameter, some strategy needs to be used to generate parameter names for the embeddable's sub-attributes (and sub-subattributes, etc.); these names must match the parameter names defined for the stored procedure in the database; * for a positional embeddable parameter, some strategy needs to be used so that the order of the embeddable's sub-attributes (and sub-subattributes, etc.) matches the order of the parameters defined for the stored procedure in the database (is this possible)?

    Hibernate JIRA | 11 months ago | Gail Badner
    java.lang.IllegalArgumentException: Type cannot be null
  2. 0

    There is nothing in the API that prevents an embeddable parameter to be mapped for a stored procedure. For example, with Address is an embeddable: {code} @NamedStoredProcedureQuery( name = "User.findAddressById", resultClasses = User.class, procedureName = "PROC", parameters = { @StoredProcedureParameter(mode = ParameterMode.IN, name = "ID_PARAM", type = Integer.class), @StoredProcedureParameter(mode = ParameterMode.OUT, name = "ADDRESS_PARAM", type = Address.class) } ) {code} When Hibernate tries to create the stored procedure, the following exception is thrown: {noformat} java.lang.IllegalArgumentException: Type cannot be null at org.hibernate.procedure.internal.AbstractParameterRegistrationImpl.setHibernateType(AbstractParameterRegistrationImpl.java:187) at org.hibernate.procedure.internal.AbstractParameterRegistrationImpl.<init>(AbstractParameterRegistrationImpl.java:124) at org.hibernate.procedure.internal.AbstractParameterRegistrationImpl.<init>(AbstractParameterRegistrationImpl.java:97) at org.hibernate.procedure.internal.NamedParameterRegistration.<init>(NamedParameterRegistration.java:35) at org.hibernate.procedure.internal.ProcedureCallImpl.<init>(ProcedureCallImpl.java:235) at org.hibernate.procedure.internal.ProcedureCallMementoImpl.makeProcedureCall(ProcedureCallMementoImpl.java:65) at org.hibernate.internal.SessionImpl.createNamedStoredProcedureQuery(SessionImpl.java:3636) at org.hibernate.jpa.test.procedure.StoreProcedureOutParameterByNameTest.testNamedBasicAndEmbeddableOutParameters(StoreProcedureOutParameterByNameTest.java:127) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.hibernate.testing.junit4.ExtendedFrameworkMethod.invokeExplosively(ExtendedFrameworkMethod.java:45) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:74) {noformat} The Hibernate type for the embeddable is null because the ParameterMemento constructor passes the value returned by {{sessionFactory.getTypeResolver().heuristicType( type.getName() )}}, which returns {{null}}. In addition the following needs to be resolved to support this improvement: * for a named embeddable parameter, some strategy needs to be used to generate parameter names for the embeddable's sub-attributes (and sub-subattributes, etc.); these names must match the parameter names defined for the stored procedure in the database; * for a positional embeddable parameter, some strategy needs to be used so that the order of the embeddable's sub-attributes (and sub-subattributes, etc.) matches the order of the parameters defined for the stored procedure in the database (is this possible)?

    Hibernate JIRA | 11 months ago | Gail Badner
    java.lang.IllegalArgumentException: Type cannot be null

    Root Cause Analysis

    1. java.lang.IllegalArgumentException

      Type cannot be null

      at org.hibernate.procedure.internal.AbstractParameterRegistrationImpl.setHibernateType()
    2. org.hibernate.procedure
      ProcedureCallMementoImpl.makeProcedureCall
      1. org.hibernate.procedure.internal.AbstractParameterRegistrationImpl.setHibernateType(AbstractParameterRegistrationImpl.java:187)
      2. org.hibernate.procedure.internal.AbstractParameterRegistrationImpl.<init>(AbstractParameterRegistrationImpl.java:124)
      3. org.hibernate.procedure.internal.AbstractParameterRegistrationImpl.<init>(AbstractParameterRegistrationImpl.java:97)
      4. org.hibernate.procedure.internal.NamedParameterRegistration.<init>(NamedParameterRegistration.java:35)
      5. org.hibernate.procedure.internal.ProcedureCallImpl.<init>(ProcedureCallImpl.java:235)
      6. org.hibernate.procedure.internal.ProcedureCallMementoImpl.makeProcedureCall(ProcedureCallMementoImpl.java:65)
      6 frames
    3. Hibernate
      SessionImpl.createNamedStoredProcedureQuery
      1. org.hibernate.internal.SessionImpl.createNamedStoredProcedureQuery(SessionImpl.java:3636)
      1 frame
    4. org.hibernate.jpa
      StoreProcedureOutParameterByNameTest.testNamedBasicAndEmbeddableOutParameters
      1. org.hibernate.jpa.test.procedure.StoreProcedureOutParameterByNameTest.testNamedBasicAndEmbeddableOutParameters(StoreProcedureOutParameterByNameTest.java:127)
      1 frame
    5. Java RT
      DelegatingMethodAccessorImpl.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      3 frames
    6. JUnit
      FrameworkMethod.invokeExplosively
      1. org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
      2. org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      3. org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
      3 frames
    7. A Hibernate O/RM Module
      ExtendedFrameworkMethod.invokeExplosively
      1. org.hibernate.testing.junit4.ExtendedFrameworkMethod.invokeExplosively(ExtendedFrameworkMethod.java:45)
      1 frame
    8. JUnit
      FailOnTimeout$StatementThread.run
      1. org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      2. org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      3. org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
      4. org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:74)
      4 frames