I'm trying to store my RecurringOrderProductVariationDTO in the db, but am getting an ArrayIndexOutOfBoundsException. I've created a test to isolate the problem, but have been unsuccessful figuring out where I've gone astray.
The popular cause of this problem seems to be an error in the mapping file, but I'm wondering if this has something to do with my data initialization.
Thanks for any help you can provide...
Hibernate version: 2.1.3
Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class
name="com.companyx.commons.datatransfer.RecurringOrderProductVariationDTO"
table="tRecurringOrderProductVariation"
>
<id
name="uidPk"
type="int"
column="UID_PK"
>
<generator class="native">
<param name="sequence"></param>
</generator>
</id>
<property
name="recurringOrderID"
type="int"
column="recurringOrderID"
not-null="true"
length="4"
/>
<property
name="productVariationID"
type="int"
column="productVariationID"
not-null="true"
length="4"
/>
<property
name="quantity"
type="int"
column="quantity"
not-null="true"
length="4"
/>
<property
name="price"
type="java.math.BigDecimal"
column="price"
not-null="true"
length="9"
/>
<property
name="deleted"
type="boolean"
column="deleted"
not-null="true"
length="1"
/>
<property
name="note"
type="java.lang.String"
column="note"
length="500"
/>
<!-- associations -->
<!-- bi-directional one-to-many association to Topva -->
<bag
name="orderProductVariationAttributes"
lazy="true"
inverse="true" >
<key>
<column name="orderProductVariationUID" />
</key>
<one-to-many
class="com.merchantspace.commons.datatransfer.OrderProductVariationAttributeDTO"
/>
</bag>
<!-- bi-directional many-to-one association to TattributeGroup -->
<many-to-one
name="attributeGroup"
class="com.merchantspace.commons.datatransfer.AttributeGroupDTO"
>
<column name="attributeGroupUID" />
</many-to-one>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
// test created to isolate the problem
public void testDelete() throws Exception {
int origNum = recurringOrderProductVariationDAO.list().size();
List productList = recurringOrderProductVariationDAO.find(ropvDTO); //Exception occurs here
... <code cut for brevity>
}
//RecurringOrderProductVariationDAO.find
public List find(RecurringOrderProductVariationDTO roDTO) throws Exception {
Session session = HibernateUtil.currentSession();
Transaction txn = null;
try {
return session.createCriteria(RecurringOrderProductVariationDTO.class)
.add(Example.create(roDTO).ignoreCase())
.list();
} catch (Exception ex) {
throw ex;
} finally {
HibernateUtil.closeSession();
}
}
// initializes all not-null data...show to give an example of data.
private void setupDTO() {
ropvDTO = new RecurringOrderProductVariationDTO();
ropvDTO.setRecurringOrderID(orderID.intValue());
ropvDTO.setProductVariationID(95); // the Auchentoshen
ropvDTO.setDeleted(false);
ropvDTO.setQuantity(1);
ropvDTO.setPrice(new BigDecimal(89.99));
ropvDTO.setNote("good stuff!");
}
// HibernateUtil.currentSession
public static Session currentSession() throws HibernateException
{
configureHibernate();
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
if (s == null)
{
if (testMode)
{
//If testing is enabled run the test environment
Connection conn = HibernateTestUtil.getDBConnection();
s = sessionFactory.openSession(conn);
}
else
{
s = sessionFactory.openSession();
}
session.set(s);
}
return s;
}
// HibernateUtil.closeSession
public static void closeSession() throws HibernateException
{
Session s = (Session) session.get();
session.set(null);
if (s != null)
s.close();
}
Full stack trace of any exception that occurs:Code:
java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at com.microsoft.jdbc.sqlserver.tds.TDSRPCParameter.write(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.submitRequest(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.execute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:800)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:189)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:955)
at net.sf.hibernate.loader.Loader.list(Loader.java:946)
at net.sf.hibernate.loader.CriteriaLoader.list(CriteriaLoader.java:121)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3604)
at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:238)
at com.companyx.dataaccess.hibernate.RecurringOrderProductVariationDAO.find(RecurringOrderProductVariationDAO.java:89)
at test.companyx.SCR_0001.TestRecurringOrderProductVariationDAO.testDelete(TestRecurringOrderProductVariationDAO.java:88)
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:324)
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 com.borland.jbuilder.unittest.JBTestRunner.a(Unknown Source)
at com.borland.jbuilder.unittest.JBTestRunner.initiateTest(Unknown Source)
at com.borland.jbuilder.unittest.JBTestRunner.main(Unknown Source)
Name and version of the database you are using: SQL Server 2000
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: