-->
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.  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Getting java.lang.ArrayIndexOutOfBoundsException
PostPosted: Sun Sep 07, 2003 11:38 pm 
I am testing my mapping/persistence classes. The configuration/mappings include a lot of one-to-many mappings. So, I am loading only a few tables with data.

In my case, I am trying to create an entry or the parent by filling in all the fields except the bi-directional one-to-many association with its children.

Following is the JUnit stack trace:

java.lang.ArrayIndexOutOfBoundsException: 1
at net.sf.hibernate.util.ArrayHelper.slice(ArrayHelper.java:59)
at net.sf.hibernate.loader.OuterJoinLoader.walkComponentTree(OuterJoinLoader.java:230)
at net.sf.hibernate.loader.OuterJoinLoader.walkClassTree(OuterJoinLoader.java:191)
at net.sf.hibernate.loader.OuterJoinLoader.walkTree(OuterJoinLoader.java:74)
at net.sf.hibernate.loader.OneToManyLoader.<init>(OneToManyLoader.java:57)
at net.sf.hibernate.collection.CollectionPersister.createCollectionQuery(CollectionPersister.java:268)
at net.sf.hibernate.collection.CollectionPersister.<init>(CollectionPersister.java:259)
at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:216)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:627)
at norc.enum.dao.HibernateDAOFactory.configSessionFactory(HibernateDAOFactory.java:141)
at norc.enum.dao.HibernateDAOFactory.<init>(HibernateDAOFactory.java:67)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at java.lang.Class.newInstance0(Class.java:308)
at java.lang.Class.newInstance(Class.java:261)
at norc.enum.dao.AbstractDAOFactory.getFactory(AbstractDAOFactory.java:22)
at norc.enum.dao.test.NsTimeTableDAOImplTest.setUp(NsTimeTableDAOImplTest.java:40)
at junit.framework.TestCase.runBare(TestCase.java:125)
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:396)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:280)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:172)


Am I missing anything here. I have my relationships mapped as bi-directional one-to-many from the parent to the child as follows:

<set name="children1"
table="children1_table"
inverse="true"
cascade="save-update">
<key column="children1_table_id" />
<one-to-many class="Children1" />
</set>


My test is as follows:

Parent p = new Parent();
p.setProp1("Prop1 value");
p.setDate(new Date());
p.setUserId(11111111L);
...
//already set up the sessionFactory mapping before and all was fine
try{
session = HibernateDAOFactory.getSession();
session.save(p);
}catch(HibernateException e){
//do something here.
}

I do not even get to catch the Hibernate exception. I get an exception way before.

Any help is really appreciated as I could not find why this is happening in the documentation, which I followed to the word in setting this example up.

Thanks.


Top
  
 
 Post subject: one more thing..
PostPosted: Sun Sep 07, 2003 11:41 pm 
My attempts to obfuscate the code was not complete. But the code I provide is exactly as my implementation. If you look at the stack trace you will see DAO classes. These classes are tested directly without any over the wire calls from client to server. So that should not be an issue. The DAO is only setting up the sessionFactory and making the calls to Hibernate's session to save.

Thanks.


Top
  
 
 Post subject:
PostPosted: Sun Sep 07, 2003 11:41 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Please show me the whole mapping, with the <component> definition.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 07, 2003 11:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I bet you have a <composite-id> class somewhere, and a <many-to-one> inside a <component>. Show me something like that. (might not be a composite-id association, it might be some kind of custom type)


Top
 Profile  
 
 Post subject: Here is the whole mapping
PostPosted: Sun Sep 07, 2003 11:55 pm 
Hi Gavin,

THanks for taking the time again. I would really like this to work and have really tried a bunch of things. I just cannot see why I am getting this error at this point.

I have changed the mapping in the parent a little (just changed names) to mean something in this context. But my mapping is exactly like the one below. I have a parent with a collection of children (one-to-many) with a foreign key constraint from the child to the parent (parent_id). When I create and save a parent with no children, I get the error shown above. Not sure what is going. THanks.

Mapping for parent:

<hibernate-mapping>

<class
name="Parent"
table="parent_table"
>
<meta attribute="implements">net.sf.hibernate.Lifecycle</meta>
<meta attribute="implements">net.sf.hibernate.Validatable</meta>
<id
name="parentTableId"
type="java.lang.String"
column="time_table_id"
>
<generator class="uuid.hex" />
</id>
<property
name="prop1"
type="java.lang.Object"
column="prop1"
length="11"
/>
<property
name="someId"
type="long"
column="some_id"
not-null="true"
length="10"
/>

<property
name="date"
type="java.sql.Timestamp"
column="some_dt"
length="23"
/>

<!-- associations -->

<set name="children"
table="children1_table"
inverse="true"
cascade="save-update">
<key column="parent_id" />
<one-to-many class="Child" />
</set>

</class>
</hibernate-mapping>


Mapping for child:

<hibernate-mapping>

<class
name="Child"
table="child_table"
>
<meta attribute="implements">net.sf.hibernate.Lifecycle</meta>
<meta attribute="implements">net.sf.hibernate.Validatable</meta>
<id
name="childId"
type="java.lang.String"
column="child_id"
>
<generator class="uuid.hex" />
</id>
<property
name="someProp"
type="java.sql.Timestamp"
column="some_propcolumn"
length="23"
/>

<!-- associations -->

<many-to-one name="parent" class="Parent"
column="parent_id" />
</class>
</hibernate-mapping>


Top
  
 
 Post subject:
PostPosted: Mon Sep 08, 2003 12:01 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Dude, you are not showing me the relevant mapping!


Look at the stack trace:

Quote:
at net.sf.hibernate.loader.OuterJoinLoader.walkComponentTree(OuterJoinLoader.java:230)



Somewhere in your mapping you have a component or something. You are looking in the Wrong Place!


Top
 Profile  
 
 Post subject: Okay...
PostPosted: Mon Sep 08, 2003 12:18 am 
This is the stack trace I got from a JUnit test I ran against the example mapping I posted. I am not sure why I would post a stack trace other than the one I got as a result of running the example. I was hoping through a simplification of my database mapping whihc includes 21 mapping files, I could get some guidance as to where I should look for the problem.

Lets step away from the code for a second. I basically have a bunch of classes with the following structure:

Parent -> Child1 -> Child2 (Child of Child1) -> child3 (Child of Child2).

The mapping from each parent to the corresponding child is exactly as I showed in my last posting. It is a one-to-many with inverse=true in the parent. And a many-to-one from the child to the parent.

The thing is that I do not even get to executing the test code where I try to create an instance of Parent (top most parent).

So, to be more specific, can I create a parent with no Children entries in the database? children set references will be set to null. Even more specific, whey would the error I got arise? In what situations would I get an ArrayIndexOutOfBoundsException in this case (given the call stack)?


General guidance telling me where I need to look would be very helpful.

Thanks.


Top
  
 
 Post subject:
PostPosted: Mon Sep 08, 2003 12:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Dude, you are NOT LISTENING to me!


That stack trace comes from another one of the 21 mapping documents that you refuse to show me!!

If you compile only the mappings you have shown me, you WILL NOT get that stack trace!



geeez......


Top
 Profile  
 
 Post subject: Just one comment..
PostPosted: Mon Sep 08, 2003 1:26 am 
Gavin,

I am not asking you to debug my mapping/code DUDE :). Figuring out that there is an issue in the mapping somewhere is implicit. But thanks for pointing that one out. A step in the right direction. Typically, it seems that the issue is a combination of mapping/code/database model with Hibernate and any other ORM tool.

I am basically presenting a simplified situation where I am seeing an error. Assuming that you are an expert on this tool, I was hoping you can point out why such an Exception would be raised. Off course, I was thinking that certain errors fall into some category where you can tell me look for such and such if you have a lot of one-to-many bi-directional associations with...etc...

Dumping 1000's of lines of mappings is not better (nor more practical) way to tackle this than presenting a simplified situation.

In any case, thanks for taking the time.


Top
  
 
 Post subject:
PostPosted: Mon Sep 08, 2003 4:37 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
If you turn on logging to debug level, hibernate will show which mapping files it is working on. The one right before the stack trace is usually the culprit.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 08, 2003 12:00 pm 
Newbie

Joined: Wed Oct 08, 2003 11:27 am
Posts: 18
I get the same exception while trying to build a SessionFactory. Here are my mapping files. I'm using Oracle. BTW on hsqldb it works fine.

------------------reservation.hbm.xml------------------------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>

<!--
Created by Middlegen Hibernate plugin

http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->

<class
name="airline.hibernate.Reservation"
table="RESERVATIONS"
>
<meta attribute="implements">net.sf.hibernate.Validatable</meta>
<composite-id name="comp_id" class="airline.hibernate.ReservationPK">
<key-property name="reservationId" column="RESERVATION_ID" type="int"/>
<key-property name="personId" column="PERSON_ID" type="int"/>
<key-property name="flightId" column="FLIGHT_ID" type="int"/>
</composite-id>
<property
name="registrationUtc"
type="java.sql.Timestamp"
column="REGISTRATION_UTC"
not-null="true"
length="7"
/>
<property
name="commentary"
type="java.lang.String"
column="COMMENTARY"
length="200"
/>

<!-- associations -->
<!-- bi-directional many-to-one association to Person -->
<many-to-one
name="person"
class="airline.hibernate.Person"
not-null="true"
insert="false"
update="false"
>
<column name="PERSON_ID" />
</many-to-one>
<!-- bi-directional many-to-one association to Flight -->
<many-to-one
name="flight"
class="airline.hibernate.Flight"
not-null="true"
insert="false"
update="false"
>
<column name="FLIGHT_ID" />
</many-to-one>

</class>
</hibernate-mapping>

-----------------------------person.hbm.xml-----------------------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>

<!--
Created by Middlegen Hibernate plugin

http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->

<class
name="airline.hibernate.Person"
table="PERSONS"
schema="cmsd"
>
<meta attribute="implements">net.sf.hibernate.Validatable</meta>
<id
name="personId"
type="int"
column="PERSON_ID"
>
<generator class="sequence">
<param name="sequence"></param>
</generator>
</id>
<property
name="firstName"
type="java.lang.String"
column="FIRST_NAME"
not-null="true"
length="32"
/>
<property
name="lastName"
type="java.lang.String"
column="LAST_NAME"
not-null="true"
length="32"
/>
<property
name="description"
type="java.lang.Object"
column="DESCRIPTION"
length="4000"
/>

<!-- associations -->
<!-- bi-directional one-to-many association to Reservation -->
<set
name="reservations"
lazy="true"
inverse="true"
>
<key>
<column name="PERSON_ID" />
</key>
<one-to-many
class="airline.hibernate.Reservation"
/>
</set>

</class>
</hibernate-mapping>


-----------------------------flight.hbm.xml-----------------------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>

<!--
Created by Middlegen Hibernate plugin

http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->

<class
name="airline.hibernate.Flight"
table="FLIGHTS"
schema="cmsd"
>
<meta attribute="implements">net.sf.hibernate.Validatable</meta>
<id
name="flightId"
type="int"
column="FLIGHT_ID"
>
<generator class="sequence">
<param name="sequence"></param>
</generator>
</id>
<property
name="name"
type="java.lang.String"
column="NAME"
not-null="true"
length="32"
/>
<property
name="departureUtc"
type="java.sql.Timestamp"
column="DEPARTURE_UTC"
not-null="true"
length="7"
/>
<property
name="arrivalUtc"
type="java.sql.Timestamp"
column="ARRIVAL_UTC"
not-null="true"
length="7"
/>

<!-- associations -->
<!-- bi-directional one-to-many association to Reservation -->
<set
name="reservations"
lazy="true"
inverse="true"
>
<key>
<column name="FLIGHT_ID" />
</key>
<one-to-many
class="airline.hibernate.Reservation"
/>
</set>

</class>
</hibernate-mapping>
-----------------------------------------------------------------------------

Somebody, please let me know what's wrong.
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 08, 2003 12:14 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Quote:
<generator class="sequence">
<param name="sequence"></param>
</generator>


Your sequence param should be filled with the oracle sequence name.

BTW, hsqldb does not support sequence: I don't know how hibernate deals with a mapping using an unsupported feature.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 08, 2003 12:18 pm 
Newbie

Joined: Wed Oct 08, 2003 11:27 am
Posts: 18
You're right. I'm sorry, I meant that the same tables but with the mapping files adapted to hsqldb are working fine. :)
Thanks for pointing out the the missing sequence.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 08, 2003 12:32 pm 
Newbie

Joined: Wed Oct 08, 2003 11:27 am
Posts: 18
Are you sure that this is the problem, because I set a sequence(UNIQUE_ID is default on Oracle) and I still get the error. Here is my output:


Oct 8, 2003 7:28:31 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: Hibernate 2.0.3
Oct 8, 2003 7:28:32 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=net.sf.hibernate.dialect.OracleDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.jdbc.batch_size=0, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.query.imports=net.sf.hibernate.test, net.sf.hibernate.eg, hibernate.proxool.pool_alias=pool1, hibernate.connection.username=cmsd, hibernate.connection.url=jdbc:oracle:thin:@10.0.0.131:1521:CMS, hibernate.show_sql=false, hibernate.connection.password=cmsd, hibernate.statement_cache.size=25, hibernate.connection.pool_size=1}
Oct 8, 2003 7:28:32 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: using java.io streams to persist binary types
Oct 8, 2003 7:28:32 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
Oct 8, 2003 7:28:32 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: JVM proxy support: true
Oct 8, 2003 7:28:32 PM net.sf.hibernate.cfg.Configuration addClass
INFO: Mapping resource: airline/hibernate/Flight.hbm.xml
Oct 8, 2003 7:28:33 PM net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: airline.hibernate.Flight -> FLIGHTS
Oct 8, 2003 7:28:33 PM net.sf.hibernate.cfg.Configuration addClass
INFO: Mapping resource: airline/hibernate/Person.hbm.xml
Oct 8, 2003 7:28:33 PM net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: airline.hibernate.Person -> PERSONS
Oct 8, 2003 7:28:33 PM net.sf.hibernate.cfg.Configuration addClass
INFO: Mapping resource: airline/hibernate/Reservation.hbm.xml
Oct 8, 2003 7:28:33 PM net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: airline.hibernate.Reservation -> RESERVATIONS
Oct 8, 2003 7:28:34 PM net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-many association mappings
Oct 8, 2003 7:28:34 PM net.sf.hibernate.cfg.Binder bindCollectionSecondPass
INFO: Mapping collection: airline.hibernate.Flight.reservations -> RESERVATIONS
Oct 8, 2003 7:28:34 PM net.sf.hibernate.cfg.Binder bindCollectionSecondPass
INFO: Mapping collection: airline.hibernate.Person.reservations -> RESERVATIONS
Oct 8, 2003 7:28:34 PM net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
Oct 8, 2003 7:28:34 PM net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Oct 8, 2003 7:28:34 PM net.sf.hibernate.dialect.Dialect <init>
INFO: Using dialect: net.sf.hibernate.dialect.OracleDialect
Oct 8, 2003 7:28:34 PM net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 1
Oct 8, 2003 7:28:34 PM net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@10.0.0.131:1521:CMS
Oct 8, 2003 7:28:34 PM net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=cmsd, password=cmsd}
Oct 8, 2003 7:28:34 PM net.sf.hibernate.ps.PreparedStatementCache <init>
INFO: prepared statement cache size: 25
Oct 8, 2003 7:28:34 PM net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: Use outer join fetching: true
Oct 8, 2003 7:28:35 PM net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: Use scrollable result sets: true
java.lang.ArrayIndexOutOfBoundsException: 1
at net.sf.hibernate.util.ArrayHelper.slice(ArrayHelper.java:59)
at net.sf.hibernate.loader.OuterJoinLoader.walkComponentTree(OuterJoinLoader.java:230)
at net.sf.hibernate.loader.OuterJoinLoader.walkClassTree(OuterJoinLoader.java:191)
at net.sf.hibernate.loader.OuterJoinLoader.walkAssociationTree(OuterJoinLoader.java:353)
at net.sf.hibernate.loader.OuterJoinLoader.walkAssociationTree(OuterJoinLoader.java:155)
at net.sf.hibernate.loader.OuterJoinLoader.walkClassTree(OuterJoinLoader.java:176)
at net.sf.hibernate.loader.OuterJoinLoader.walkTree(OuterJoinLoader.java:74)
at net.sf.hibernate.loader.OneToManyLoader.<init>(OneToManyLoader.java:57)
at net.sf.hibernate.collection.CollectionPersister.createCollectionQuery(CollectionPersister.java:277)
at net.sf.hibernate.collection.CollectionPersister.<init>(CollectionPersister.java:268)
at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:216)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:627)
at ro.level7.common.db.Manager.configure(Manager.java:31)
at ro.level7.common.db.Manager.main(Manager.java:52)
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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
java.lang.NullPointerException
at ro.level7.common.db.Manager.main(Manager.java:87)
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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
Exception in thread "main" Process terminated with exit code 1


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 08, 2003 1:37 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Daniel Moldovan wrote:
Are you sure that this is the problem,

Actually, I pretty sure this is not ;-). But certainly would have been your next problem.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 17 posts ]  Go to page 1, 2  Next

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.