-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate tries to bind a wrong data to its PreparedStatemen
PostPosted: Wed Aug 31, 2005 8:18 am 
Newbie

Joined: Wed Aug 31, 2005 7:24 am
Posts: 3
Location: Jakarta Indonesia
Im trying to insert a new unpersisted object PositionObserver.
PositionObserver is extending Device (sourcecode provided).
When i testing the saving operation, i got these exception
Code:
JDBCExceptionReporter:63 - could not insert: [com.iwatch.ids.persistence.PositionObserver] [insert into DEVICE (CLIENTID, ENABLED, IMEI_NO, MSISDN_NO, DEVICE_NO, GPRS_OBSERVE, MMS_OBSERVE, SMS_OBSERVE, DEVICE_TYPE, DEVICEID) values (?, ?, ?, ?, ?, ?, ?, ?, 'OBSERVER', ?)]
java.sql.SQLException: Parameter index out of range (10 > number of parameters, which is 9).

Please take a look at the provided stacktrace.

At the debug level log, it seems that Hibernate is trying to bind unknown
value to the prepared statement :

Code:
18:09:59,851 DEBUG SQL:324 - insert into DEVICE (CLIENTID, ENABLED, IMEI_NO, MSISDN_NO, DEVICE_NO, GPRS_OBSERVE, MMS_OBSERVE, SMS_OBSERVE, DEVICE_TYPE, DEVICEID) values (?, ?, ?, ?, ?, ?, ?, ?, 'OBSERVER', ?)
18:09:59,851 DEBUG AbstractBatcher:377 - preparing statement
18:09:59,851 DEBUG BasicEntityPersister:1671 - Dehydrating entity: [com.iwatch.ids.persistence.PositionObserver#CUST00000]
18:09:59,851 DEBUG StringType:60 - binding 'CORP00000' to parameter: 1
18:09:59,851 DEBUG BooleanType:60 - binding 'true' to parameter: 2
18:09:59,851 DEBUG StringType:60 - binding '123123123' to parameter: 3
18:09:59,851 DEBUG StringType:60 - binding '123123123' to parameter: 4
18:09:59,851 DEBUG StringType:60 - binding '123123123' to parameter: 5
18:09:59,851 DEBUG IntegerType:60 - binding '3' to parameter: 6
18:09:59,851 DEBUG BooleanType:60 - binding 'true' to parameter: 7
18:09:59,851 DEBUG BooleanType:60 - binding 'true' to parameter: 8
18:09:59,851 DEBUG BooleanType:60 - binding 'true' to parameter: 9
18:09:59,851 DEBUG StringType:60 - binding 'CUST00000' to parameter: 10


As you can see that Hibernate is trying to bind
Code:
IntegerType:60 - binding '3' to parameter: 6


I think this causes the error. Yielding java.sql.SQLException: Parameter index out of range (10 > number of parameters, which is 9)
Is this a bug or a miss use ?
Do i miss something ?
How can i fix this problem ?

Hibernate version:
hibernate-3.1beta1
hibernate-annotations-3.1beta3

Mapping documents:
hibernate.cfg.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory name="IwatchSession">
        <property name="hibernate.connection.url">jdbc:mysql://localhost/ids</property>
        <property name="hibernate.cglib.use_reflection_optimizer">true</property>
        <property name="hibernate.connection.password">root</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
      <property name="hibernate.show_sql">true</property>
      
       <mapping package="com.iwatch.ids.persistence"/>
          <mapping class="com.iwatch.ids.persistence.Client"/>
          <mapping class="com.iwatch.ids.persistence.CorporateClient"/>
          <mapping class="com.iwatch.ids.persistence.Device"/>
          <mapping class="com.iwatch.ids.persistence.GpsReporter"/>
          <mapping class="com.iwatch.ids.persistence.GpsTrack"/>
          <mapping class="com.iwatch.ids.persistence.PositionObserver"/>
          <mapping class="com.iwatch.ids.persistence.ReporterObserver"/>
          <mapping class="com.iwatch.ids.persistence.ReporterStation"/>
          <mapping class="com.iwatch.ids.persistence.RetailClient"/>
          <mapping class="com.iwatch.ids.persistence.Station"/>
          <mapping class="com.iwatch.ids.persistence.TrafficLog"/>
          <mapping class="com.iwatch.ids.persistence.log.GprsTrafficLog"/>
          <mapping class="com.iwatch.ids.persistence.log.SmsMmsTrafficLog"/>
    </session-factory>
</hibernate-configuration>


Device.java
Code:
package com.iwatch.ids.persistence;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import javax.persistence.AccessType;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratorType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.apache.log4j.Logger;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import org.hibernate.annotations.OptimisticLockType;
import org.hibernate.criterion.Expression;


@Entity(access = AccessType.PROPERTY)
@org.hibernate.annotations.Entity(
      mutable=false,
      optimisticLock=OptimisticLockType.NONE,
      selectBeforeUpdate=true, dynamicInsert = true, dynamicUpdate = true
)
@Table(name="DEVICE")
@Inheritance(
    strategy=InheritanceType.SINGLE_TABLE,
    discriminatorType=DiscriminatorType.STRING,
    discriminatorValue="DEVICE"
)
@DiscriminatorColumn(name="DEVICE_TYPE")
public class Device {
   
   public static final Logger logger = Logger.getLogger(Device.class);

   public static final int TYPE_CELLPHONE = 0;
   public static final int TYPE_SMARTPHONE = 1;
   public static final int TYPE_PDAPHONE = 2;
   public static final int TYPE_CUSTOM_DEVICE = 3;
   
   private String deviceId;
   private String deviceNumber;
   private String deviceMsisdn;
   private String deviceImei;
   private Boolean enabled = false;
   private Integer deviceType = TYPE_CELLPHONE;
   
   private Collection<TrafficLog> trafficLogs = new ArrayList<TrafficLog>();
   private Client client;
   
   @ManyToOne( cascade = {CascadeType.MERGE} )
    @JoinColumn(name="CLIENTID")
   public Client getClient() {
      return client;
   }
   
   public void setClient(Client client) {
      this.client = client;
   }
   
   @Id(generate=GeneratorType.NONE)
   @Column(name = "DEVICEID", length = 16)
   public String getDeviceId() {
      return deviceId;
   }
   
   public void setDeviceId(String deviceId) {
      this.deviceId = deviceId;
   }
   
   @Basic(fetch = FetchType.EAGER)
   @Column(updatable = true, name = "IMEI_NO", nullable = true, length = 32)
   public String getDeviceImei() {
      return deviceImei;
   }
   
   public void setDeviceImei(String deviceImei) {
      this.deviceImei = deviceImei;
   }
   
   @Basic(fetch = FetchType.EAGER)
   @Column(updatable = true, name = "MSISDN_NO", nullable = true, length = 32)
   public String getDeviceMsisdn() {
      return deviceMsisdn;
   }
   
   public void setDeviceMsisdn(String deviceMsisdn) {
      this.deviceMsisdn = deviceMsisdn;
   }
   
   @Basic(fetch = FetchType.EAGER)
   @Column(updatable = true, name = "DEVICE_NO", nullable = true, length = 16)
   public String getDeviceNumber() {
      return deviceNumber;
   }
   
   public void setDeviceNumber(String deviceNumber) {
      this.deviceNumber = deviceNumber;
   }
   
   @Basic(fetch = FetchType.EAGER)
   @Column(updatable = true, name = "DEVICE_TYPE", nullable = true)
   public Integer getDeviceType() {
      return deviceType;
   }
   
   public void setDeviceType(Integer deviceType) {
      this.deviceType = deviceType;
   }
   
   @Basic(fetch = FetchType.EAGER)
   @Column(updatable = true, name = "ENABLED", nullable = true)
   public Boolean getEnabled() {
      return enabled;
   }
   
   public void setEnabled(Boolean enabled) {
      this.enabled = enabled;
   }
   
   @OneToMany(mappedBy="device", fetch = FetchType.LAZY, cascade = {CascadeType.REMOVE})
   @OnDelete(action=OnDeleteAction.CASCADE)
   public Collection<TrafficLog> getTrafficLogs() {
      return trafficLogs;
   }
   
   public void setTrafficLogs(Collection<TrafficLog> trafficLogs) {
      this.trafficLogs = trafficLogs;
   }
   
   public void addTrafficLog(TrafficLog trafficLog) {
      trafficLogs.add(trafficLog);
      trafficLog.setDevice(this);
   }

   public void removeTrafficLog(TrafficLog trafficLog) {
      trafficLogs.remove(this);
      if(trafficLog.getDevice().equals(this)) {
         trafficLog.setDevice(null);
      }
   }
   
   /******************************************************************
    * Persistence Oriented Methods.
    ******************************************************************/
   
   public static int countTotalDevices(Session hbmSession) {
      String qString = "select count(device) from com.iwatch.ids.persistence.Device device";
      Query query = hbmSession.createQuery(qString);
      Iterator i = query.iterate();
      if(i.hasNext()) {
         Object o = i.next();
         if(o instanceof Integer) {
            return ((Integer) o).intValue();
         } else if(o instanceof String) {
            return Integer.parseInt((String) o);
         }
      }
      return 0;
   }
   
   public static int countDevicesByPrefix(Session hbmSession, String prefix) {
      String qString = "select count(device) from com.iwatch.ids.persistence.Device" +
      " device where device.deviceId like :prefixPattern";
      Query query = hbmSession.createQuery(qString).setString("prefixPattern", prefix + "%");
      Iterator i = query.iterate();
      if(i.hasNext()) {
         Object o = i.next();
         if(o instanceof Integer) {
            return ((Integer) o).intValue();
         } else if(o instanceof String) {
            return Integer.parseInt((String) o);
         }
      }
      return 0;
   }
   
   public String save(Session hbmSession, String prefix) {
      if(getClient() == null) {
         throw new IllegalStateException("Trying to save device that is not belong to any client. Try to set the client of this device.");
      }
      String id = generateDeviceID(hbmSession, prefix);
      setDeviceId(id);
      hbmSession.save(this);
      return id;
   }
   
   public void update(Session hbmSession) {
      hbmSession.update(this);
   }
   
   public void remove(Session hbmSession) {
      hbmSession.delete(this);
   }
   
   public static void removeDevice(Session hbmSession, String deviceID) {
      try {
         Device device = loadDeviceById(hbmSession, deviceID);
         device.remove(hbmSession);
      }
      catch(HibernateException he) {
         logger.warn("Attempt to delete non-existent Device Object. ID " + deviceID);
      }
   }
   
   public static boolean isDeviceIdExist(Session hbmSession, String deviceId) {
      Device device = (Device) hbmSession.get(Device.class, deviceId);
      if(device == null) {
         return false;
      } else {
         return true;
      }
   }
   
   public static Device loadDeviceById(Session hbmSession, String deviceId) {
      return (Device) hbmSession.load(Device.class, deviceId);
   }
   
   public static Device loadDeviceByNumber(Session hbmSession, String number) {
      Criteria crit = hbmSession.createCriteria(Device.class).add(Expression.eq("deviceNumber", number));
      List list = crit.list();
      if(list.size() > 0) {
         return (Device) list.get(0);
      } else {
         return null;
      }
   }
   
   public static Device loadDeviceByImei(Session hbmSession, String imei) {
      Criteria crit = hbmSession.createCriteria(Device.class).add(Expression.eq("deviceImei", imei));
      List list = crit.list();
      if(list.size() > 0) {
         return (Device) list.get(0);
      } else {
         return null;
      }
   }
   
   private String generateDeviceID(Session hbmSession, String prefix) {
      String qString = "select max(device.deviceId) from com.iwatch.ids.persistence.Device" +
            " device where device.deviceId like :prefixPattern";
      Query query = hbmSession.createQuery(qString).setString("prefixPattern", prefix + "%");
      Iterator i = query.iterate();
      if(i.hasNext()) {
         Object o = i.next();
         if(o == null) return prefix + "00000";
         if(o instanceof String) {
            String id = (String) o;
            String numbers = id.substring(prefix.length());
            int num = Integer.parseInt(numbers);
            num++;
            String nums = String.valueOf(num);
            while(nums.length() < 5)
               nums = "0" + nums;
            nums = prefix + nums;
            logger.debug("max id : " + id + ". number part : " + numbers + ". new id : " + nums);
            return nums;
         } else {
            assert (o instanceof String) : "Queried maximum value of deviceId in Device persistence is not an instance of String.";
            return o.toString();
         }
      } else {
         return prefix + "00000";
      }
   }
}


PositionObserver.java
Code:
package com.iwatch.ids.persistence;

import java.util.ArrayList;
import java.util.Collection;

import javax.persistence.AccessType;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.OneToMany;

import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

@Entity(access = AccessType.PROPERTY)
@Inheritance(
    discriminatorValue="OBSERVER"
)
public class PositionObserver extends Device {
   
   private Boolean gprsEnabled;
   private Boolean mmsEnabled;
   private Boolean smsEnabled;
   
   private Collection<ReporterObserver> reporters = new ArrayList<ReporterObserver>();

   @Basic(fetch = FetchType.EAGER)
   @Column(updatable = true, name = "GPRS_OBSERVE", nullable = true)
   public Boolean getGprsEnabled() {
      return gprsEnabled;
   }

   public void setGprsEnabled(Boolean gprsEnabled) {
      this.gprsEnabled = gprsEnabled;
   }

   @Basic(fetch = FetchType.EAGER)
   @Column(updatable = true, name = "MMS_OBSERVE", nullable = true)
   public Boolean getMmsEnabled() {
      return mmsEnabled;
   }

   public void setMmsEnabled(Boolean mmsEnabled) {
      this.mmsEnabled = mmsEnabled;
   }
   
   @OneToMany(mappedBy="observer", fetch = FetchType.LAZY, cascade = {CascadeType.REMOVE})
   @OnDelete(action=OnDeleteAction.CASCADE)
   public Collection<ReporterObserver> getReporters() {
      return reporters;
   }

   public void setReporters(Collection<ReporterObserver> reporters) {
      this.reporters = reporters;
   }

   @Basic(fetch = FetchType.EAGER)
   @Column(updatable = true, name = "SMS_OBSERVE", nullable = true)
   public Boolean getSmsEnabled() {
      return smsEnabled;
   }

   public void setSmsEnabled(Boolean smsEnabled) {
      this.smsEnabled = smsEnabled;
   }
   
}


Code between sessionFactory.openSession() and session.close():
JUnit Test Case
Code:
package com.iwatch.ids.persistence;

import junit.framework.TestCase;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.joda.time.DateTime;

public class PersistenceTest extends TestCase {

   private Session hbmSession = null;
      
   public void testCreateDevice() throws Exception {
      RetailClient retail = null;
      CorporateClient corporate = null;
      Client[] clients = Client.listAllClient(hbmSession);
      for(Client client : clients) {
         if(client instanceof RetailClient) {
            retail = (RetailClient) client;
         } else if(client instanceof CorporateClient) {
            corporate = (CorporateClient) client;
         }
      }
      if(retail == null || corporate == null) {
         fail("Cannot continue");
      }
      PositionObserver observer = new PositionObserver();
      observer.setClient(corporate);
      observer.setDeviceImei("123123123");
      observer.setDeviceMsisdn("123123123");
      observer.setDeviceNumber("123123123");
      observer.setDeviceType(PositionObserver.TYPE_CUSTOM_DEVICE);
      observer.setEnabled(true);
      observer.setGprsEnabled(true);
      observer.setSmsEnabled(true);
      observer.setMmsEnabled(true);
      Transaction tx = hbmSession.beginTransaction();
      String deviceOneKey = observer.save(hbmSession, "CUST");
      tx.commit();
      assertEquals(deviceOneKey, observer.getDeviceId());
      
   }
   
   @Override
   protected void setUp() throws Exception {
      hbmSession = HibernateUtil.getSession();
   }

   @Override
   protected void tearDown() throws Exception {
      if(hbmSession.isConnected() || hbmSession.isOpen()) {
         hbmSession.close();
      }
   }

}



Full stack trace of any exception that occurs:
Complete lines from Debug Log. Log Snippets
Code:
18:09:59,866 DEBUG JDBCExceptionReporter:63 - could not insert: [com.iwatch.ids.persistence.PositionObserver] [insert into DEVICE (CLIENTID, ENABLED, IMEI_NO, MSISDN_NO, DEVICE_NO, GPRS_OBSERVE, MMS_OBSERVE, SMS_OBSERVE, DEVICE_TYPE, DEVICEID) values (?, ?, ?, ?, ?, ?, ?, ?, 'OBSERVER', ?)]
java.sql.SQLException: Parameter index out of range (10 > number of parameters, which is 9).
   at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:2242)
   at com.mysql.jdbc.PreparedStatement.setString(PreparedStatement.java:2897)
   at org.hibernate.type.StringType.set(StringType.java:24)
   at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:63)
   at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:45)
   at org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1687)
   at org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1653)
   at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1909)
   at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2275)
   at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:48)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:227)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:284)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:748)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:329)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
   at com.iwatch.ids.persistence.PersistenceTest.testCreateDevice(PersistenceTest.java:106)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
18:09:59,866  WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState: S1009
18:09:59,866 ERROR JDBCExceptionReporter:72 - Parameter index out of range (10 > number of parameters, which is 9).
18:09:59,882 ERROR AbstractFlushingEventListener:287 - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: could not insert: [com.iwatch.ids.persistence.PositionObserver]
   at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
   at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1928)
   at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2275)
   at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:48)

   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:227)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:284)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:748)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:329)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
   at com.iwatch.ids.persistence.PersistenceTest.testCreateDevice(PersistenceTest.java:106)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.sql.SQLException: Parameter index out of range (10 > number of parameters, which is 9).
   at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:2242)
   at com.mysql.jdbc.PreparedStatement.setString(PreparedStatement.java:2897)
   at org.hibernate.type.StringType.set(StringType.java:24)
   at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:63)
   at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:45)
   at org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1687)
   at org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1653)
   at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1909)
   ... 26 more


Name and version of the database you are using:
MySQL 4.0.17 (Windows XP)

The generated SQL (show_sql=true):
Code:
insert into DEVICE (CLIENTID, ENABLED, IMEI_NO, MSISDN_NO, DEVICE_NO, GPRS_OBSERVE, MMS_OBSERVE, SMS_OBSERVE, DEVICE_TYPE, DEVICEID) values (?, ?, ?, ?, ?, ?, ?, ?, 'OBSERVER', ?)


Debug level Hibernate log excerpt:
Lines from Debug Log. Log-level Debug.
Code:
18:09:59,851 DEBUG SQL:324 - insert into DEVICE (CLIENTID, ENABLED, IMEI_NO, MSISDN_NO, DEVICE_NO, GPRS_OBSERVE, MMS_OBSERVE, SMS_OBSERVE, DEVICE_TYPE, DEVICEID) values (?, ?, ?, ?, ?, ?, ?, ?, 'OBSERVER', ?)
18:09:59,851 DEBUG AbstractBatcher:377 - preparing statement
18:09:59,851 DEBUG BasicEntityPersister:1671 - Dehydrating entity: [com.iwatch.ids.persistence.PositionObserver#CUST00000]
18:09:59,851 DEBUG StringType:60 - binding 'CORP00000' to parameter: 1
18:09:59,851 DEBUG BooleanType:60 - binding 'true' to parameter: 2
18:09:59,851 DEBUG StringType:60 - binding '123123123' to parameter: 3
18:09:59,851 DEBUG StringType:60 - binding '123123123' to parameter: 4
18:09:59,851 DEBUG StringType:60 - binding '123123123' to parameter: 5
18:09:59,851 DEBUG IntegerType:60 - binding '3' to parameter: 6
18:09:59,851 DEBUG BooleanType:60 - binding 'true' to parameter: 7
18:09:59,851 DEBUG BooleanType:60 - binding 'true' to parameter: 8
18:09:59,851 DEBUG BooleanType:60 - binding 'true' to parameter: 9
18:09:59,851 DEBUG StringType:60 - binding 'CUST00000' to parameter: 10
18:09:59,866 DEBUG AbstractBatcher:298 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
18:09:59,866 DEBUG AbstractBatcher:409 - closing statement
18:09:59,866 DEBUG JDBCExceptionReporter:63 - could not insert: [com.iwatch.ids.persistence.PositionObserver] [insert into DEVICE (CLIENTID, ENABLED, IMEI_NO, MSISDN_NO, DEVICE_NO, GPRS_OBSERVE, MMS_OBSERVE, SMS_OBSERVE, DEVICE_TYPE, DEVICEID) values (?, ?, ?, ?, ?, ?, ?, ?, 'OBSERVER', ?)]
java.sql.SQLException: Parameter index out of range (10 > number of parameters, which is 9).
   at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:2242)
   at com.mysql.jdbc.PreparedStatement.setString(PreparedStatement.java:2897)
   at org.hibernate.type.StringType.set(StringType.java:24)



Top
 Profile  
 
 Post subject: Solved
PostPosted: Wed Aug 31, 2005 11:55 am 
Newbie

Joined: Wed Aug 31, 2005 7:24 am
Posts: 3
Location: Jakarta Indonesia
Sorry guys. Problem solved.

The device class have a same descriminator column name with one of the
property's column name. My mistake.

Code:
@DiscriminatorColumn(name="DEVICE_TYPE")
public class Device {
    ...
   @Basic(fetch = FetchType.EAGER)
   @Column(updatable = true, name = "DEVICE_TYPE", nullable = true)
   public Integer getDeviceType() {
      return deviceType;
   }
   ...
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.