-->
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.  [ 5 posts ] 
Author Message
 Post subject: ArrayIndexOutOfBoundsException on find
PostPosted: Fri Feb 11, 2005 5:10 pm 
Newbie

Joined: Fri Feb 11, 2005 1:41 pm
Posts: 3
Location: Indianapolis, IN USA
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:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 11, 2005 5:12 pm 
Newbie

Joined: Fri Feb 11, 2005 1:41 pm
Posts: 3
Location: Indianapolis, IN USA
Here's the DTO class too just in case...

Code:
package com.disetronic.commons.datatransfer;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

import org.apache.commons.lang.builder.ToStringBuilder;

/**
* <p>Title: RecurringOrderProductVariationDTO</p>
*
* <p>Description: The products contained within a recurring order</p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: Disetronic USA</p>
*
* @author not attributable
* @version 1.0
*/
public class RecurringOrderProductVariationDTO implements Serializable{
        // identifier field
        private Integer uidPk;

        // recurring order foreign key
        private int recurringOrderID;

        // product variation foreign key
        private int productVariationID;

        /** persistent field */
        private int quantity;

        /** persistent field */
        private BigDecimal price;

        /** persistent field */
        private boolean deleted;

        /** nullable persistent field */
        private String note;

        /** persistent field */
        private com.merchantspace.commons.datatransfer.AttributeGroupDTO attributeGroup;

        /** persistent field */
        private List orderProductVariationAttributes;

        public RecurringOrderProductVariationDTO() {
        }

        public RecurringOrderProductVariationDTO(int uid,
                                                 int recurringOrderID,
                                                 int productVariationID,
                                                 int quantity,
                                                 BigDecimal price,
                                                 boolean deleted,
                                                 String note,
                                                 com.merchantspace.commons.datatransfer.AttributeGroupDTO attributeGroup,
                                                 List orderProductVariationAttributes) {
            this.uidPk = new Integer(uid);
            this.recurringOrderID = recurringOrderID;
            this.productVariationID = productVariationID;
            this.quantity = quantity;
            this.price = price;
            this.note = note;
            this.deleted = deleted;
            this.attributeGroup = attributeGroup;
            this.orderProductVariationAttributes = orderProductVariationAttributes;
        }

        public RecurringOrderProductVariationDTO(String note,
                                                 com.merchantspace.commons.datatransfer.AttributeGroupDTO attributeGroup,
                                                 List orderProductVariationAttributes) {
            this.note = note;
            this.attributeGroup = attributeGroup;
            this.orderProductVariationAttributes = orderProductVariationAttributes;
        }

        public Integer getUidPk() {
            return this.uidPk;
        }

        public void setUidPk(Integer id) {
            this.uidPk = id;
        }

        public int getRecurringOrderID() {
            return this.recurringOrderID;
        }

        public void setRecurringOrderID(int recurringOrderID) {
            this.recurringOrderID = recurringOrderID;
        }

        public int getProductVariationID() {
            return this.productVariationID;
        }

        public void setProductVariationID(int productVariationID) {
            this.productVariationID = productVariationID;
        }

        public int getQuantity() {
            return this.quantity;
        }

        public void setQuantity(int quantity) {
            this.quantity = quantity;
        }

        public BigDecimal getPrice() {
            return this.price;
        }

        public void setPrice(BigDecimal price) {
            this.price = price;
        }

        public boolean isDeleted() {
            return this.deleted;
        }

        public void setDeleted(boolean deleted) {
            this.deleted = deleted;
        }

        public String getNote() {
            return this.note;
        }

        public void setNote(String note) {
            this.note = note;
        }

        public com.merchantspace.commons.datatransfer.AttributeGroupDTO getAttributeGroup() {
            return this.attributeGroup;
        }

        public void setAttributeGroup(com.merchantspace.commons.datatransfer.AttributeGroupDTO attributeGroup) {
            this.attributeGroup = attributeGroup;
        }

        public List getOrderProductVariationAttributes() {
            return this.orderProductVariationAttributes;
        }

        public void setOrderProductVariationAttributes(List
                orderProductVariationAttributes) {
            this.orderProductVariationAttributes = orderProductVariationAttributes;
        }

        public String toString() {
            return new ToStringBuilder(this)
                .append("uidPk", getUidPk())
                .toString();
        }

}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 12, 2005 5:06 pm 
jTDS Developer
jTDS Developer

Joined: Tue Feb 24, 2004 5:36 pm
Posts: 70
Location: Bucharest, Romania
This is a MS JDBC driver issue. Don't use that. It's not recommended for use with Hibernate (or otherwise ;o) ).

See the Hibernate Compatibility Guide for a list of drivers you can use with SQL Server. I would recommend jTDS, of course, but please note that I'm a jTDS developer.

Alin,
The jTDS Project.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 15, 2005 9:22 am 
Newbie

Joined: Fri Feb 11, 2005 1:41 pm
Posts: 3
Location: Indianapolis, IN USA
Thanks, using jTDS does solve the problem. I am curious what part of my code is triggering the exception from the MS SQL Server driver, especially since the creator of the package that uses Hibernate (which I am customizing) recommends the MS driver.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 15, 2005 9:34 am 
jTDS Developer
jTDS Developer

Joined: Tue Feb 24, 2004 5:36 pm
Posts: 70
Location: Bucharest, Romania
I think it has to do with LOBs. The MS driver has known problems with LOBs and that's something one would use System.arraycopy() for (notice it tries to write a RPC parameter, probably to the output stream, when this happens).

Alin.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.