-->
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.  [ 12 posts ] 
Author Message
 Post subject: mny-to-one cause ArrayIndexOutofBoundsException
PostPosted: Thu Jan 15, 2004 7:28 am 
Beginner
Beginner

Joined: Mon Sep 22, 2003 7:16 am
Posts: 25
i implemented a 1-M relations as follows
Code:
<class name="OrderVO" table="order">
   <composite-id>
      <key-property name="id" column="o_id" type="string"/>
      <key-property name="office" column="o_office" type="string"/>
   </composite-id>
   ... some properties
   <set name="orderDetails" table="order_detail" inverse="true" lazy="true" >
      <key>
         <column name="od_order_id"/>
         <column name="od_office"/>
      </key>
      <one-to-many class="OrderDetailVO"/>   
   </set>
</class>

<class name="OrderDetailVO" table="order_detail">
   <composite-id>
      <key-property name="detailId" column="od_id" type="string"/>
      <key-property name="office" column="od_office" type="string"/>
   </composite-id>
   <property name="orderId" column="od_order_id" type="string"/>
   ... some properties
   <!--
   <many-to-one name="Order" class="OrderVO" not-null="true">
      <column name="od_order_id"/>
      <column name="od_office"/>
   </many-to-one>
   -->
</class>

If I uncomment the <many-to-one> in orderDetail, an ArrayIndexOutOfBoundsException raised:
Code:
java.lang.ArrayIndexOutOfBoundsException: 33
        at com.mysql.jdbc.PreparedStatement.set(Unknown Source)
        at com.mysql.jdbc.PreparedStatement.setString(Unknown Source)
        at net.sf.hibernate.type.StringType.set(StringType.java:22)
        at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:45)
        at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:30)
        at net.sf.hibernate.type.ComponentType.nullSafeSet(ComponentType.java:166)
        at net.sf.hibernate.persister.EntityPersister.dehydrate(EntityPersister.java:367)
        at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:444)
        at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:20)
        at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2063)
        at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2035)
        at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:1979)
        at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:56)
        at air.agent.oceanexport.action.ShipperBookingOrderDetailAction.endTransaction(Unknown Source)
        at air.agent.oceanexport.action.ShipperBookingOrderDetailAction.execute(Unknown Source)
...

I've tried: cascade="all" & "all-delete-orphan", removing the "not-null". None worked.
I have no clue what I'm missing...
Though refering to the section of "Bidirectional one to many", cascade is not essential, I'd like some suggestion on using the cascade in this case.
Any help would be appreciated. Thx in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2004 7:34 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Please post the offending java code and the statement that hibernate is executing.

Justin


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2004 9:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
And post a Hibernate log


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2004 10:19 pm 
Beginner
Beginner

Joined: Mon Sep 22, 2003 7:16 am
Posts: 25
The code:
Code:
OrderDetailVO od = new OrderDetailVO();
OrderVO o = (OrderVO) session.find("from OrderVO o where o.id = '" + id + "' and o.office = '" + office + "' ").iterator().next();
od.setId();
od.setOrder(o);
od.setOtherPropertiesIncludingOffice();
//o.getOrderDetails().add(od);   // No effect
session.save(sbod);
try {
   session.flush();
} catch (Exception e) {
   logger.error(e);   // Exceptions when trying to flush/commit
}


Top
 Profile  
 
 Post subject: The log
PostPosted: Thu Jan 15, 2004 10:32 pm 
Beginner
Beginner

Joined: Mon Sep 22, 2003 7:16 am
Posts: 25
To improve the readability, I modified the class names and the id column in the questions as:
ShipperBookingOrderVO -> OrderVO
ShipperBookingOrderVO.bookingId -> OrderVO.id
ShipperBookingOrderDetailVO -> OrderDetailVO
ShipperBookingOrderDetailVO.bookingDetailId -> OrderDetailVO.id
ShipperBookingOrderDetailVO.bookingId -> OrderDetailVO.orderId
Code:
...
148587 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.impl.SessionImpl  - saving [sls.valueobject.ShipperBookingOrderDetailVO#sls.valueobject.ShipperBookingOrderDetailVO@e0ba9bda]
148598 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.impl.SessionImpl  - flushing session
148598 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.impl.SessionImpl  - Flushing entities and processing referenced collections
148599 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.impl.SessionImpl  - Collection found: [sls.valueobject.ShipperBookingOrderVO.shipperBookingOrderDetails#sls.valueobject.ShipperBookingOrderVO@656cfea9], was: [sls.valueobject.ShipperBookingOrderVO.shipperBookingOrderDetails#sls.valueobject.ShipperBookingOrderVO@656cfea9]
148600 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.impl.SessionImpl  - Collection found: [sls.valueobject.ShipperBookingOrderVO.truckingOrder#sls.valueobject.ShipperBookingOrderVO@656cfea9], was: [sls.valueobject.ShipperBookingOrderVO.truckingOrder#sls.valueobject.ShipperBookingOrderVO@656cfea9]
148600 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.impl.SessionImpl  - Collection found: [sls.valueobject.ShipperBookingOrderVO.customDoc#sls.valueobject.ShipperBookingOrderVO@656cfea9], was: [sls.valueobject.ShipperBookingOrderVO.customDoc#sls.valueobject.ShipperBookingOrderVO@656cfea9]
148601 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.persister.AbstractEntityPersister  - air.core.common.valueobject.SeqTableVO.seqNumber is dirty
148601 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.impl.SessionImpl  - Updating entity: [air.core.common.valueobject.SeqTableVO#air.core.common.valueobject.SeqTableVO@722d3f5]
148606 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.impl.SessionImpl  - Processing unreferenced collections
148606 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.impl.SessionImpl  - Scheduling collection removes/(re)creates/updates
148606 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.impl.SessionImpl  - Flushed: 1 insertions, 1 updates, 0 deletions to 3 objects
148606 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.impl.SessionImpl  - Flushed: 0 (re)creations, 0 updates, 0 removals to 3 collections
148607 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.impl.SessionImpl  - executing flush
148607 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.persister.EntityPersister  - Inserting entity: sls.valueobject.ShipperBookingOrderDetailVO#sls.valueobject.ShipperBookingOrderDetailVO@e0ba9bda
148608 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.impl.BatcherImpl  - 1 open PreparedStatements
148608 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.impl.SessionFactoryImpl  - prepared statement get: insert into shipper_booking_order_detail (sbod_status, sbod_pkgs, sbod_ctns, sbod_pieces, sbod_unit_price, sbod_qty, sbod_lbs, sbod_kgs, sbod_net_lbs, sbod_net_kgs, sbod_cbf, sbod_cbm, sbod_length, sbod_width, sbod_depth, sbod_description, sbod_marks, sbod_commodity_code, sbod_commodity_description, sbod_ref_type1, sbod_ref_type2, sbod_ref_type3, sbod_ref_type4, sbod_ref_code1, sbod_ref_code2, sbod_ref_code3, sbod_ref_code4, sbod_cargo_in_date, sbod_seq, sbod_loading_seq, sbod_booking_id, sbod_booking_detail_id, sbod_office) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
148608 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.impl.SessionFactoryImpl  - preparing statement
148609 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.persister.EntityPersister  - Dehydrating entity: sls.valueobject.ShipperBookingOrderDetailVO#sls.valueobject.ShipperBookingOrderDetailVO@e0ba9bda
148609 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.StringType  - binding 'SHSE040100046' to parameter: 1
148610 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.StringType  - binding 'O' to parameter: 2
148610 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.StringType  - binding '5' to parameter: 3
148610 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.IntegerType  - binding '6' to parameter: 4
148611 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.IntegerType  - binding '7' to parameter: 5
148611 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.DoubleType  - binding '15.0' to parameter: 6
148612 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.IntegerType  - binding '16' to parameter: 7
148612 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.DoubleType  - binding '2.0' to parameter: 8
148612 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.DoubleType  - binding '1.0' to parameter: 9
148613 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.DoubleType  - binding '4.0' to parameter: 10
148613 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.DoubleType  - binding '3.0' to parameter: 11
148613 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.DoubleType  - binding '9.0' to parameter: 12
148614 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.DoubleType  - binding '8.0' to parameter: 13
148614 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.DoubleType  - binding '10.0' to parameter: 14
148614 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.DoubleType  - binding '11.0' to parameter: 15
148614 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.DoubleType  - binding '12.0' to parameter: 16
148615 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.StringType  - binding 'd1' to parameter: 17
148615 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.StringType  - binding 'm1' to parameter: 18
148615 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.StringType  - binding 'c1' to parameter: 19
148616 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.StringType  - binding 'cd1' to parameter: 20
148616 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.StringType  - binding 'PO Number' to parameter: 21
148616 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.StringType  - binding 'PO Number' to parameter: 22
148616 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.StringType  - binding 'Style Number' to parameter: 23
148617 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.StringType  - binding 'Style Number' to parameter: 24
148617 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.StringType  - binding 'r1' to parameter: 25
148617 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.StringType  - binding 'r2' to parameter: 26
148617 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.StringType  - binding 'r3' to parameter: 27
148618 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.StringType  - binding 'r4' to parameter: 28
148618 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.DateType  - binding '01 January 2003' to parameter: 29
148619 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.IntegerType  - binding '748' to parameter: 30
148620 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.IntegerType  - binding '0' to parameter: 31
148620 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.StringType  - binding 'SHSE040100046' to parameter: 32
148621 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.StringType  - binding 'SHA' to parameter: 33
148621 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.type.StringType  - binding 'OE2004000000748' to parameter: 34
148622 [16-Jan-2004 10:22:06] ERROR air.agent.oceanexport.action.ShipperBookingOrderDetailAction  - java.lang.ArrayIndexOutOfBoundsException: 33
148623 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.transaction.JDBCTransaction  - commit
148623 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.impl.SessionImpl  - flushing session
148623 [16-Jan-2004 10:22:06] DEBUG net.sf.hibernate.impl.SessionImpl  - Flushing entities and processing referenced collections
...


Error at 148622. Thx in advance.


Top
 Profile  
 
 Post subject: i suspect ...
PostPosted: Thu Jan 15, 2004 10:47 pm 
Beginner
Beginner

Joined: Mon Sep 22, 2003 7:16 am
Posts: 25
the prepared statement binded an extra bookingId into parameter 1.

in the java, the bookingOrderDetailVO.bookingId I collected is already set.
then i set bind bookingOrderVO into it...

is it the cause of the error?
should i unset the original bookingId or remove the binding of orderVO?


Top
 Profile  
 
 Post subject: not working
PostPosted: Thu Jan 15, 2004 11:47 pm 
Beginner
Beginner

Joined: Mon Sep 22, 2003 7:16 am
Posts: 25
i tried:
- unsetting the bookingId when creating the orderDetail, then bind the order into it -> ArrayOutOfBound with the 1st parameter = null
- let the bookingId as is and skip binding order into orderDetail -> NullPointerException ....

any clue?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2004 12:56 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
I suspect your problem lies in the following mapping code:
Code:
   <many-to-one name="Order" class="OrderVO" not-null="true">
      <column name="od_order_id"/>
      <column name="od_office"/>
   </many-to-one>


In particular what relationship are you trying to define using:
Code:
<column name="od_office"/>


Just use:
Code:
<many-to-one name="Order" class="OrderVO" not-null="true" column="xxx" />

...where xxx is the fk column in the order_detail table.


Top
 Profile  
 
 Post subject: ...
PostPosted: Fri Jan 16, 2004 2:11 am 
Beginner
Beginner

Joined: Mon Sep 22, 2003 7:16 am
Posts: 25
But Order have a composite key = (id, office)

i noticed an duplicate column order id in orderDetail so i remove that the OrderDetail xml becomes:
Code:
<class name="OrderDetailVO" table="order_detail">
   <composite-id>
      <key-property name="detailId" column="od_id" type="string"/>
      <key-property name="office" column="od_office" type="string"/>
   </composite-id>
   ... some properties
   <!--
   <many-to-one name="Order" class="OrderVO" not-null="true">
      <column name="od_order_id"/>
      <column name="od_office"/>
   </many-to-one>
   -->
</class>


Yet, there are duplicated office in the insert statement which lead to ArrayIndexOutOfBounds...
What should I do with a compound key that used part of the foreign key?
ie: 1 M
key (a,b) (b,c)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2004 6:52 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
<class name="OrderDetailVO" table="order_detail">
   <composite-id>
      <key-property name="detailId" column="od_id" type="string"/>
      <key-property name="office" column="od_office" type="string"/>
   </composite-id>
   <property name="orderId" column="od_order_id" type="string"/>
   ... some properties
   <many-to-one name="Order" class="OrderVO" not-null="true">
      <column name="od_order_id"/>
      <column name="od_office"/>
   </many-to-one>
</class>

This is not allowed, the many-to-one is set by the user when he do orderDetailVO.setOrder(order);
So it can't be a part of the pk. Add a new column for many-to-one od_office

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 16, 2004 6:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Just use insert="false" update="false" for the <many-to-one> mapping. (Actually Hibernate should have warned you of this! What version of Hibernate is it?)


Top
 Profile  
 
 Post subject: I'm using 2.0.3
PostPosted: Fri Jan 16, 2004 10:14 pm 
Beginner
Beginner

Joined: Mon Sep 22, 2003 7:16 am
Posts: 25
i'll update to 2.1.1 later... Any precautions I've to make for the upgrade?

Since I cannot modify the database and setting update & insert to false make me unable to set the order id into order detail, i'll give up the <many-to-one> and load the order for each order detail, if needed, in the application...

Thx a lot.

^_^


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