Message:
A new issue has been created in JIRA.
---------------------------------------------------------------------
View the issue:
http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-208
Here is an overview of the issue:
---------------------------------------------------------------------
Key: HB-208
Summary: ArrayIndexOutOfBoundsException is thrown when an attempt is make to save a polymorphic object (with discriminator column)
Type: Bug
Status: Unassigned
Priority: Critical
Project: Hibernate2
Components:
core
Versions:
2.0.2
Assignee:
Reporter: Ferdinand Che
Created: Tue, 22 Jul 2003 8:03 AM
Updated: Tue, 22 Jul 2003 8:03 AM
Environment: XP, JBoss-3.2.1, JDK-1.4.1_02,MySQL-4.0.12-max-nt
Description:
An ArrayIndexOutOfBoundsException is thrown when an attempt is made to save (e.g. session.save(obj);session.flush();) that is a subclass (see mapping extract below). This exception is thrown at the point where the underlying preparedstatement is being populated with data following a net.sf.hibernate.type.StringType.set()-->line 22; following a call to EntityPersister.dehydrate() folowing an EntityPersister.insert().
On further inspection I have been able to determine that this is caused by a line in EntityPersister.generateInsertString() --> specifically: insert.addColumn(getDiscriminatorColumnName(), discriminatorSQLString); This line is only called because in this scenario we are handling polymorphic behaviour. the trouble is that this conflicts with the other underlying handling of object properties. The above call effectively overrides what what should appear in the resultant sql from something like (... (?,?,?,?) to an sql containing something like (?,?,'2',?). The trouble is then that when it comes to populating the prepared statement the there is one index more than is required and 'bang' ... an ArrayIndexOutOfBoundsException is thrown.
This can be 'fixed' by completely removing the line: insert.addColumn(getDiscriminatorColumnName(), discriminatorSQLString); and of cause the if statement associated with it Or making sure that the Property.isInsertable() returns false for all discriminator columns. I have used the former as a temporary fix until I get further feedback from the hibernate people.
The following is an example extract from mapping file that will trigger this issue:
<class name="com.mycom.data.ITestItem table="ITEMS">
<id name="code" column="CODE" type="string" unsaved-value="any">
<generator class="assigned">
</generator>
</id>
<discriminator column="TYPE" type="string" />
<property name="name" type="java.lang.String" column="NAME" not-null="true" />
<property name="desc" type="java.lang.String" column="DESCR" not-null="true" />
<property name="type" type="int" column="TYPE" not-null="true" />
<subclass name="com.mycom.data.TestItemType1" discriminator-value="1" />
<subclass name="com.mycom.data.TestItemType2" discriminator-value="2" />
</class>
---------------------------------------------------------------------
JIRA INFORMATION:
This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
|