java.sql.SQLException: Invalid parameter index 2.

Hibernate JIRA | Jason Stiefel | 1 decade 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

    Attempting to perform a simple find: from UserTransaction trans where trans.user = ? I'm passing the user with a type of Hibernate.OBJECT. The SQL generated is: [junit] Hibernate: select usertransa0_.guid as guid, usertransa0_.type as type, usertransa0_.user_guid as user_guid, user transa0_.partner_guid as partner_3_, usertransa0_.occured as occured, usertransa0_.user_active_state as user_act6_, usertrans a0_.user_timebank_adjustment as user_tim7_, usertransa0_.user_timebank_media_format as user_tim8_, usertransa0_.user_timebank _balance as user_tim9_ from AiaTransaction usertransa0_ where usertransa0_.type in (3, 2, 4, 1) and ((usertransa0_.user_guid= ? )) As you can see only a single "?" placeholder is present in the SQL. But I'm getting this exception (debug output included): [junit] 17:03:59,968 DEBUG [impl.BatcherImpl] preparing statement [junit] 17:03:59,968 DEBUG [type.ClassType] binding 'com.aebn.aia.core.domain.User' to parameter: 1 [junit] 17:03:59,968 DEBUG [util.SerializationHelper] Starting serialization of object [4028815a016e1aa901016e1ab737000e] [junit] 17:03:59,983 DEBUG [type.SerializableType] binding '2c6d8085f480a0b4b0b2b8b8b1b5e1b0b1b6e5b1e1e1b9b0b1b0b1b6e5b1e 1e2b7b3b7b0b0b0e5' to parameter: 2 [junit] 17:03:59,983 DEBUG [util.SerializationHelper] Starting serialization of object [4028815a016e1aa901016e1ab737000e] [junit] 17:03:59,999 DEBUG [util.JDBCExceptionReporter] SQL Exception [junit] java.sql.SQLException: Invalid parameter index 2. [junit] at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.getParameter(JtdsPreparedStatement.java:239) [junit] at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.setParameter(JtdsPreparedStatement.java:311) [junit] at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.setBytes(JtdsPreparedStatement.java:468) [junit] at net.sf.hibernate.type.BinaryType.set(BinaryType.java:28) [junit] at net.sf.hibernate.type.SerializableType.set(SerializableType.java:28) [junit] at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:48) [junit] at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:35)

    Hibernate JIRA | 1 decade ago | Jason Stiefel
    java.sql.SQLException: Invalid parameter index 2.
  2. 0

    Attempting to perform a simple find: from UserTransaction trans where trans.user = ? I'm passing the user with a type of Hibernate.OBJECT. The SQL generated is: [junit] Hibernate: select usertransa0_.guid as guid, usertransa0_.type as type, usertransa0_.user_guid as user_guid, user transa0_.partner_guid as partner_3_, usertransa0_.occured as occured, usertransa0_.user_active_state as user_act6_, usertrans a0_.user_timebank_adjustment as user_tim7_, usertransa0_.user_timebank_media_format as user_tim8_, usertransa0_.user_timebank _balance as user_tim9_ from AiaTransaction usertransa0_ where usertransa0_.type in (3, 2, 4, 1) and ((usertransa0_.user_guid= ? )) As you can see only a single "?" placeholder is present in the SQL. But I'm getting this exception (debug output included): [junit] 17:03:59,968 DEBUG [impl.BatcherImpl] preparing statement [junit] 17:03:59,968 DEBUG [type.ClassType] binding 'com.aebn.aia.core.domain.User' to parameter: 1 [junit] 17:03:59,968 DEBUG [util.SerializationHelper] Starting serialization of object [4028815a016e1aa901016e1ab737000e] [junit] 17:03:59,983 DEBUG [type.SerializableType] binding '2c6d8085f480a0b4b0b2b8b8b1b5e1b0b1b6e5b1e1e1b9b0b1b0b1b6e5b1e 1e2b7b3b7b0b0b0e5' to parameter: 2 [junit] 17:03:59,983 DEBUG [util.SerializationHelper] Starting serialization of object [4028815a016e1aa901016e1ab737000e] [junit] 17:03:59,999 DEBUG [util.JDBCExceptionReporter] SQL Exception [junit] java.sql.SQLException: Invalid parameter index 2. [junit] at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.getParameter(JtdsPreparedStatement.java:239) [junit] at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.setParameter(JtdsPreparedStatement.java:311) [junit] at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.setBytes(JtdsPreparedStatement.java:468) [junit] at net.sf.hibernate.type.BinaryType.set(BinaryType.java:28) [junit] at net.sf.hibernate.type.SerializableType.set(SerializableType.java:28) [junit] at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:48) [junit] at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:35)

    Hibernate JIRA | 1 decade ago | Jason Stiefel
    java.sql.SQLException: Invalid parameter index 2.

    Root Cause Analysis

    1. java.sql.SQLException

      Invalid parameter index 2.

      at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.getParameter()
    2. jTDS
      JtdsPreparedStatement.setBytes
      1. net.sourceforge.jtds.jdbc.JtdsPreparedStatement.getParameter(JtdsPreparedStatement.java:239)
      2. net.sourceforge.jtds.jdbc.JtdsPreparedStatement.setParameter(JtdsPreparedStatement.java:311)
      3. net.sourceforge.jtds.jdbc.JtdsPreparedStatement.setBytes(JtdsPreparedStatement.java:468)
      3 frames
    3. net.sf.hibernate
      NullableType.nullSafeSet
      1. net.sf.hibernate.type.BinaryType.set(BinaryType.java:28)
      2. net.sf.hibernate.type.SerializableType.set(SerializableType.java:28)
      3. net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:48)
      4. net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:35)
      4 frames