It seems to me there is either a bug or the possibility of a nice extension of error reporting in Hibernate 3.0.2.
Below, the RefPTR field is the 10. field in the insert sql. The value of this property is being mapped as the fifth parameter. This looks like a downright bug to me?
In addition, the "type" field (the polymorphic class discriminator) is the 11. field. The value is hardcoded in the sql. In addition, it may look as if Hibernate tries to map a NULL value to this element - or I guess this may be related to the refPTR strangeness. An extra field is bound, at least.
I would love feedback on where I messed up my mapping to get into this somewhat ... strange ... situation. It may look like the introduction of the "swaporder" property triggered these problems.
Hibernate version: 3.0.2
Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping
>
<class
name="model.Binding"
table="bindings"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
discriminator-value="null"
where="active='Y'"
>
<id
name="BID"
column="bID"
type="java.lang.Long"
unsaved-value="null"
>
<generator class="increment">
</generator>
</id>
<discriminator
column="type"
type="string"
length="1"
/>
<property
name="active"
type="char"
update="true"
insert="true"
access="property"
column="active"
not-null="true"
/>
<property
name="created"
type="java.sql.Timestamp"
update="true"
insert="true"
access="property"
column="created"
/>
<property
name="fromDate"
type="java.sql.Timestamp"
update="true"
insert="true"
access="property"
column="from_date"
not-null="false"
/>
<property
name="ordreID"
type="java.lang.Long"
update="true"
insert="true"
access="property"
column="ordreID"
not-null="false"
/>
<property
name="refPTR"
type="java.lang.Long"
update="true"
insert="true"
access="property"
column="refPTR"
not-null="false"
/>
<property
name="toDate"
type="java.sql.Timestamp"
update="true"
insert="true"
access="property"
column="to_date"
not-null="false"
/>
<many-to-one
name="user"
class="model.User"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="userID"
/>
<subclass
name="model.Terminal"
dynamic-update="false"
dynamic-insert="false"
discriminator-value="D"
>
<set
name="lineBindings"
lazy="true"
inverse="true"
cascade="none"
sort="unsorted"
where="active='Y'"
>
<key
column="refPTR"
>
</key>
<one-to-many
class="model.LineBinding"
/>
</set>
<property
name="mac"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="mac"
not-null="false"
/>
<property
name="productCode"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="product_code"
not-null="false"
/>
<property
name="serial"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="sn"
not-null="false"
/>
</subclass>
<subclass
name="model.AbstractLineBinding"
dynamic-update="false"
dynamic-insert="false"
>
<many-to-one
name="number"
class="model.Number"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="number"
/>
<subclass
name="model.LineBinding"
dynamic-update="false"
dynamic-insert="false"
discriminator-value="N"
>
<property
name="password"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="password"
not-null="false"
/>
<property
name="rank"
type="java.lang.Short"
update="true"
insert="true"
access="property"
column="rank"
not-null="false"
/>
<set
name="swapOrders"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
where="active='Y'"
>
<key
column="refPTR"
>
</key>
<one-to-many
class="model.SwapOrder"
/>
</set>
<many-to-one
name="terminal"
class="model.Terminal"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="refPTR"
not-null="false"
/>
</subclass>
<subclass
name="model.SwapOrder"
dynamic-update="false"
dynamic-insert="false"
discriminator-value="P"
>
</subclass>
</subclass>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
using DAO pattern, but:
LineBinding newnumber = new LineBinding();
newnumber.setActive('Y');
newnumber.setFromDate(new Timestamp(Calendar.getInstance().getTime().getTime()));
newnumber.setToDate(new Timestamp(Calendar.getInstance().getTime().getTime()+1000));
newnumber.setNumber(so.getNumber());
newnumber.setOrdreID(new Long(92));
newnumber.setRank(new Short("17"));
newnumber.setUser(this.getUser());
newnumber.setPassword("secret");
newnumber.setCreated(new Timestamp(Calendar.getInstance().getTime().getTime()+2000));
newnumber.setRefPTR(new Long(1001));
terminalDAO.saveObject(newnumber);
Full stack trace of any exception that occurs:
java.sql.SQLException: Parameter index out of range (12 > 11).
at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:2001)
at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:2030)
at com.mysql.jdbc.PreparedStatement.setLong(PreparedStatement.java:543)
at org.hibernate.type.LongType.set(LongType.java:40)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:62)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:44)
at org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1618)
at org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1584)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1840)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2190)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:678)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:309)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:470)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:401)
at org.springframework.transaction.interceptor.TransactionAspectSupport.doCommitTransactionAfterReturning(TransactionAspectSupport.java:256)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:67)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:606)
at model.service.TerminalService$$EnhancerByCGLIB$$4293f83d_2.provisionDevice(<generated>)
at servlet.ProvServlet.doService(ProvServlet.java:145)
at org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:384)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:344)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at com.meterware.servletunit.InvocationContextImpl.service(InvocationContextImpl.java:79)
at com.meterware.servletunit.ServletUnitClient.newResponse(ServletUnitClient.java:112)
at com.meterware.httpunit.WebWindow.getResource(WebWindow.java:164)
at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:128)
at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:121)
at com.meterware.httpunit.WebClient.getResponse(WebClient.java:113)
at com.meterware.servletunit.ServletRunner.getResponse(ServletRunner.java:151)
at servlet.AbstractDatabaseTestCase.deviceTest(AbstractDatabaseTestCase.java:206)
at no.TestDevice.testDevice(TestDevice.java:58)
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:474)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)
Name and version of the database you are using:
Mysql 3.0.20
The generated SQL (show_sql=true):
Hibernate: insert into bindings (active, created, from_date, ordreID, to_date, userID, number, password, rank, refPTR, type, bID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'N', ?)
Debug level Hibernate log excerpt:
46596 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
46596 [main] DEBUG org.hibernate.persister.entity.BasicEntityPersister - Dehydrating entity: [no.telio.model.LineBinding#2112665]
46596 [main] DEBUG org.hibernate.type.CharacterType - binding 'Y' to parameter: 1
46597 [main] DEBUG org.hibernate.type.TimestampType - binding '2005-05-06 12:25:52' to parameter: 2
46597 [main] DEBUG org.hibernate.type.TimestampType - binding '2005-05-06 12:25:50' to parameter: 3
46597 [main] DEBUG org.hibernate.type.LongType - binding '92' to parameter: 4
46597 [main] DEBUG org.hibernate.type.LongType - binding '1001' to parameter: 5
46597 [main] DEBUG org.hibernate.type.TimestampType - binding '2005-05-06 12:25:51' to parameter: 6
46597 [main] DEBUG org.hibernate.type.LongType - binding '25183' to parameter: 7
46597 [main] DEBUG org.hibernate.type.StringType - binding '4721212121' to parameter: 8
46598 [main] DEBUG org.hibernate.type.StringType - binding 'secret' to parameter: 9
46598 [main] DEBUG org.hibernate.type.ShortType - binding '17' to parameter: 10
46598 [main] DEBUG org.hibernate.type.LongType - binding null to parameter: 11
46598 [main] DEBUG org.hibernate.type.LongType - binding '2112665' to parameter: 12
46598 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
46598 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - closing statement
46604 [main] DEBUG org.hibernate.util.JDBCExceptionReporter - could not insert: [no.telio.model.LineBinding] [insert into bindings (active, created, from_date, ordreID, to_date, userID, number, password, rank, refPTR, type, bID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'N', ?)]
java.sql.SQLException: Parameter index out of range (12 > 11).
|