title: Hibernate: Parameter index out of range (8 > number of parameters, which is 7)
body: <p>Not a duplicate of this question <a href="https://stackoverflow.com/questions/17806466/parameter-index-out-of-range-8-number-of-parameters-which-is-7">Parameter index out of range (8 &gt; number of parameters, which is 7)</a></p>
  
  <p>My SaltTranDef entity class is</p>
  
  <pre><code>@Id
  @Column(name="salt_id")
  @GeneratedValue(strategy=GenerationType.IDENTITY)
  private Integer saltId;
  
  @Column(name="tran_type")
  private String transactionType;
  
  @Column(name="user_id")
  private String userId;
  
  @Column(name="parent_system")
  private String parentSystem;
  
  @Column(name="parent_sys_ref_id")
  private String parentSystemReference;
  
  @Column(name="status")
  private int status;
  
  @OneToMany(mappedBy = "saltTranDef")
  @Cascade({ org.hibernate.annotations.CascadeType.ALL,
           org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
  private Set&lt;SaltTranUser&gt; saltTranUsers;
  </code></pre>
  
  <p>And the SaltTranUser entity class is</p>
  
  <pre><code>@Id
  @Column(name="salt_id")
  private Integer saltId;
  
  @Id
  @Column(name="salt_property")
  private String saltProp;
  
  @Column(name="salt_value")
  private String saltValue;
  
  @ManyToOne
  @JoinColumn(name="salt_id")
  private SaltTranDef saltTranDef;
  </code></pre>
  
  <p>Both the above entity classes extend a mappedSuperclass</p>
  
  <pre><code>@Column(name="cre_suid")
  private String creatorId;
  
  @Column(name="mod_suid")
  private String modifiedId;
  
  @Column(name="cre_date")
  private Timestamp creationDate;
  
  @Column(name="mod_date")
  private Timestamp modificationDate;
  </code></pre>
  
  <p>When inserting from a JUnit:</p>
  
  <pre><code>@Test
  public void testInsert(){
  
      SaltTranDef std = new SaltTranDef();
      SaltTranUser stu1 = new SaltTranUser();
      SaltTranUser stu2 = new SaltTranUser();
      SaltTranUser stu3 = new SaltTranUser();
      Set&lt;SaltTranUser&gt; set1 = new HashSet&lt;SaltTranUser&gt;();
  
      Transaction tx = session.beginTransaction();
  
      std.setParentSystem("A");
      std.setParentSystemReference("123");
      std.setStatus(10);
      std.setTransactionType("A");
      std.setUserId("1234");
      std.setCreationDate(new Timestamp(new Date().getTime()));
      std.setCreatorId("1234");
  
      session.persist(std);
  //  session.flush();
  
      stu1.setCreationDate(new Timestamp(new Date().getTime()));
      stu1.setCreatorId("1234");
      stu1.setSaltProp("Fname");
      stu1.setSaltValue("Swateek");
      stu1.setSaltId(std.getSaltId());
  
      stu2.setCreationDate(new Timestamp(new Date().getTime()));
      stu2.setCreatorId("1234");
      stu2.setSaltProp("Lname");
      stu2.setSaltValue("Jena");
      stu2.setSaltId(std.getSaltId());
  
      stu3.setCreationDate(new Timestamp(new Date().getTime()));
      stu3.setCreatorId("1234");
      stu3.setSaltProp("Phone");
      stu3.setSaltValue("9900056668");
      stu3.setSaltId(std.getSaltId());
  
      set1.add(stu1);
      set1.add(stu2);
      set1.add(stu3);
  
      std.setSaltTranUsers(set1);
  
      session.save(std);
      tx.commit();
  }
  </code></pre>
  
  <p>I get an error saying:</p>
  
  <blockquote>
    <p>SEVERE: Parameter index out of range (8 > number of parameters, which is 7).
    Mar 25, 2015 8:06:35 AM org.hibernate.event.def.AbstractFlushingEventListener performExecutions
    SEVERE: Could not synchronize database state with session
    org.hibernate.exception.GenericJDBCException: could not insert: [com.salt.entity.SaltTranUser]
        at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
    Caused by: java.sql.SQLException: Parameter index out of range (8 > number of parameters, which is 7).
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)</p>
  </blockquote>