-->
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.  [ 3 posts ] 
Author Message
 Post subject: ArrayIndexOutOfBoundsException when using lists
PostPosted: Fri Feb 12, 2010 2:30 pm 
Newbie

Joined: Fri Feb 05, 2010 3:28 pm
Posts: 5
Hello Hibernators,

I have a one-to-many mapping in my code. When I changed the mapping from a <set> to a <list> (because we need to order the elements, I started getting ArrayIndexOutOfBounds exceptions

My original, working mapping file looks like this:

Code:
      <set
            name="bflySizeValues"
            lazy="true"
             inverse="true"
            cascade="none"
             >
          <key>
             <column name="BFLY_SIZE_CHART_ID"/>
          </key>
          <one-to-many
                class="com.bluefly.apps.manager.domain.BflySizeValue"
                />
      </set>

and my altered one looks like this
Code:
      <list
             name="bflySizeValues"
             inverse="true"
            cascade="all"
             >
          <key>
             <column name="BFLY_SIZE_CHART_ID"/>
          </key>
         <list-index column="SORT_ORDER" base="1"/>
          <one-to-many
                class="com.bluefly.apps.manager.domain.BflySizeValue"
                />
      </list>



My stack trace is:
Code:
Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
        at java.util.ArrayList.set(ArrayList.java:339)
        at org.hibernate.collection.PersistentList.readFrom(PersistentList.java:386)
        at org.hibernate.loader.Loader.readCollectionElement(Loader.java:1008)
        at org.hibernate.loader.Loader.readCollectionElements(Loader.java:646)
        at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:591)
        at org.hibernate.loader.Loader.doQuery(Loader.java:701)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
        at org.hibernate.loader.Loader.loadCollection(Loader.java:1998)
        at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
        at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
        at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:63)
        at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1717)
        at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
        at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
        at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:109)
        at org.hibernate.collection.PersistentList.size(PersistentList.java:91)
        at com.bluefly.apps.manager.domain.BflySizeChart.setBflySizeValues(BflySizeChart.java:165)
        ... 172 more



Can somebody help me debug this? I turned on show_sql and executed the SQL, I didn't see any suspicious data


Top
 Profile  
 
 Post subject: Re: ArrayIndexOutOfBoundsException when using lists
PostPosted: Sat Feb 13, 2010 6:48 pm 
Beginner
Beginner

Joined: Wed Nov 21, 2007 8:02 am
Posts: 48
change your base value to 0 and check if it works.

Even if that doesn't work, delete all the data from the tables (which was inserted before this change) and insert new data through the new mapping and query.

I suspect your sort_order column has 0 values for all rows


Top
 Profile  
 
 Post subject: Re: ArrayIndexOutOfBoundsException when using lists
PostPosted: Wed Feb 17, 2010 6:34 pm 
Newbie

Joined: Fri Feb 05, 2010 3:28 pm
Posts: 5
thank you. I found duplicate values for SORT_ORDER in my data, I'm suspecting thats whats causing this


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