Thx Jakob, I've changed the IndirectionHandler class in the release 2 as you recomended: public Object invoke(Object proxy, Method method, Object[] args) { Object subject = null; try { subject = getRealSubject(); // handle toString differently for non-materialized proxies // to avoid materialization due to logging. if (subject == null) { if (method.getName() == "toString") { return "unmaterialized proxy for " + getIdentity(); } else { return null; } } else { Method m = subject.getClass().getMethod(method.getName(), method.getParameterTypes()); return m.invoke(subject, args); } } catch (Exception e) { log.error("Method invoking failed for method *"+method.getName()+"* on object "+subject, e); throw new PersistenceBrokerException("Error invoking:"+method.getName(),e); } }
The following are entries in my descriptors files: <class-descriptor class = "A" proxy="dynamic" table = "A"> <field-descriptor id = "1" name = "shipmentOid" column = "SHIPMENT_OID" jdbc-type ="INTEGER" primarykey = "true" /> <field-descriptor id = "2" name = "countryCode" column = "REF_COUNTRY_CD" jdbc-type ="VARCHAR" primarykey = "true" /> ... <reference-descriptor name="ABRef" class-ref="B"> <foreignkey field-ref="shipmentOid"/> <foreignkey field-ref="countryCode"/> </reference-descriptor> </class-descriptor> <class-descriptor class = "B" proxy="dynamic" table = "B"> <field-descriptor id = "1" name = "shipmentOidPiece" column = "SHIPMENT_OID" jdbc-type ="INTEGER" primarykey = "true" /> <field-descriptor id = "2" name = "typeFlg" column = "TYPE_FLG" jdbc-type ="VARCHAR" primarykey = "true" /> ... <reference-descriptor name="counterRef" class-ref="A"> <foreignkey field-ref="shipmentOidPiece"/> <foreignkey field-ref="typeFlg"/> </reference-descriptor> </class-descriptor> I still get this error: [DEFAULT] WARN: OJB broker could not materialize com.fedex.data.CorePieceCounterImpl{188119,JP} submit flag: null [DEFAULT] WARN: OJB broker could not materialize com.fedex.data.CorePieceCounterImpl{188119,JP} Type flag: null [org.apache.ojb.broker.accesslayer.ConnectionFactoryPooledImpl] INFO: Destroy object was called, try to close connection: [EMAIL PROTECTED] Any help on this is appreciated. Thx regards, Janet ----- Original Message ----- From: "Jakob Braeuchi" <[EMAIL PROTECTED]> To: "OJB Developers List" <[EMAIL PROTECTED]> Sent: Tuesday, April 01, 2003 05:15 Subject: Re: Problems when using composite primary keys > hi janet, > > sorry, i overlooked the message in your stacktrace. > the following sample using multiple keys works for me: > > <class-descriptor > class="brj.ojb.MultiPkParent" > table="multipkparent" > > > <field-descriptor id="1" > name="id1" > column="key1" > jdbc-type="INTEGER" > primarykey="true" > /> > <field-descriptor id="2" > name="id2" > column="key2" > jdbc-type="VARCHAR" > primarykey="true" > /> > <field-descriptor id="3" > name="field1" > column="field1" > jdbc-type="VARCHAR" > /> > <field-descriptor id="4" > name="field2" > column="field2" > jdbc-type="VARCHAR" > /> > <collection-descriptor > name="children" > element-class-ref="brj.ojb.MultiPkChild" > auto-retrieve="true" > auto-update="true" > auto-delete="true" > > > <inverse-foreignkey field-ref="c_id1"/> > <inverse-foreignkey field-ref="c_id2"/> > </collection-descriptor> > </class-descriptor> > > <class-descriptor > class="brj.ojb.MultiPkChild" > table="multipkchild" > proxy="dynamic" > > > <field-descriptor id="1" > name="c_id1" > column="parent_key1" > jdbc-type="INTEGER" > primarykey="true" > /> > <field-descriptor id="2" > name="c_id2" > column="parent_key2" > jdbc-type="VARCHAR" > primarykey="true" > /> > <field-descriptor id="3" > name="field1" > column="field1" > jdbc-type="VARCHAR" > primarykey="true" > /> > <reference-descriptor > name="parent" > class-ref="brj.ojb.MultiPkParent" > > > <foreignkey field-ref="c_id1"/> > <foreignkey field-ref="c_id2"/> > </reference-descriptor> > </class-descriptor> > > jakob > > Jakob Braeuchi wrote: > > > hi janet, > > > > don't you get an error message like "[DEFAULT] WARN: OJB broker could > > not materialize ...." in the log before the npe occurs ? > > do you have access to the source of ojb ? > > if yes, please try to replace the following method in IndirectionHandler: > > > > public Object invoke(Object proxy, Method method, Object[] args) > > { > > Object subject = null; > > try > > { > > subject = getRealSubject(); > > // handle toString differently for > > non-materialized proxies > > // to avoid materialization due to logging. > > if (subject == null) > > { > > if (method.getName() == "toString") > > { > > return "unmaterialized proxy for " + getIdentity(); > > } > > else > > { > > return null; > > } > > } > > else > > { > > Method m = > > subject.getClass().getMethod(method.getName(), > > method.getParameterTypes()); > > return m.invoke(subject, args); > > } > > } > > catch (Exception e) > > { > > log.error("Method invoking failed for method > > *"+method.getName()+"* on object "+subject, e); > > throw new PersistenceBrokerException("Error > > invoking:"+method.getName(),e); > > } > > } > > > > > > hth > > jakob > > > > Janet Song wrote: > > > >> Hi, > >> > >> Thanks. Got that problem solved. It works fine when i map a compound > >> primary > >> key from one table to another with a single primary key. However when > >> i map > >> compound primary keys to compound primary keys, i get a > >> NullPointerException > >> which results from > >> [org.apache.ojb.broker.accesslayer.IndirectionHandler] > >> ERROR: Met..... > >> > >> > >> e.g Table A: > >> <class-descriptor > >> class = "com.data.A" > >> proxy="dynamic" > >> table = "Shipment"> > >> <field-descriptor id = "1" > >> name = "shipmentOid" > >> column = "SHIPMENT_OID" > >> jdbc-type ="INTEGER" > >> primarykey = "true" > >> /> > >> <field-descriptor id = "2" > >> name = "countryCode" > >> column = "REF_COUNTRY_CD" > >> jdbc-type ="VARCHAR" > >> primarykey = "true" > >> /> > >> .... > >> > >> <reference-descriptor > >> name="piece" > >> class-ref="com.data.B" > >> proxy="true"> > >> <foreignkey field-id-ref="1"/> > >> <foreignkey field-id-ref="2"/> > >> </reference-descriptor> > >> </class-descriptor> > >> > >> Table B: > >> > >> <class-descriptor > >> class = "com.data.B" > >> proxy="dynamic" > >> table = "Piece"> > >> <field-descriptor id = "1" > >> name = "shipmentOidPiece" > >> column = "SHIPMENT_OID" > >> jdbc-type ="INTEGER" > >> primarykey = "true" > >> /> > >> <field-descriptor id = "2" > >> name = "typeFlg" > >> column = "TYPE_FLG" > >> jdbc-type ="VARCHAR" > >> primarykey = "true" > >> /> > >> > >> <reference-descriptor > >> name="piece" > >> class-ref="com.data.A" > >> proxy="true"> > >> <foreignkey field-id-ref="1"/> > >> <foreignkey field-id-ref="2"/> > >> </reference-descriptor> > >> </class-descriptor> > >> > >> > >> [DEFAULT] WARN: OJB broker could not materialize > >> com.fedex.data.CorePieceCounterImpl{188119,JP} > >> [org.apache.ojb.broker.accesslayer.IndirectionHandler] ERROR: Method > >> invoking failed for method *getSubmitFlag* on object null > >> null > >> java.lang.NullPointerException > >> at > >> org.apache.ojb.broker.accesslayer.IndirectionHandler.invoke(Unknown > >> Source) > >> at $Proxy1.getSubmitFlag(Unknown Source) > >> at TestClient.testEqualCriteriaOneToOne(TestClient.java:104) > >> at TestClient.runApp(TestClient.java:78) > >> at TestClient.main(TestClient.java:71) > >> Exception in thread "main" java.lang.NullPointerException > >> at > >> org.apache.ojb.broker.accesslayer.IndirectionHandler.invoke(Unknown > >> Source) > >> at $Proxy1.getSubmitFlag(Unknown Source) > >> at TestClient.testEqualCriteriaOneToOne(TestClient.java:104) > >> at TestClient.runApp(TestClient.java:78) > >> at TestClient.main(TestClient.java:71) > >> rethrown as org.apache.ojb.broker.PersistenceBrokerException: Error > >> invoking:getSubmitFlag > >> at > >> org.apache.ojb.broker.accesslayer.IndirectionHandler.invoke(Unknown > >> Source) > >> at $Proxy1.getSubmitFlag(Unknown Source) > >> at TestClient.testEqualCriteriaOneToOne(TestClient.java:104) > >> at TestClient.runApp(TestClient.java:78) > >> at TestClient.main(TestClient.java:71) > >> Caused by: java.lang.NullPointerException > >> ... 5 more > >> > >> > >> Any help on this is appreciated. Thanks > >> > >> > >> regards. > >> > >> Janet > >> > >> ----- Original Message ----- > >> From: "Jakob Braeuchi" <[EMAIL PROTECTED]> > >> To: "OJB Developers List" <[EMAIL PROTECTED]> > >> Sent: Saturday, March 29, 2003 01:15 > >> Subject: Re: ArrayIndexOutOfBoundsException when using composite primary > >> keys > >> > >> > >> > >> > >>> hi janet, > >>> > >>> imo this problem is coming from a reference-descriptor not matching > >>> the > >>> number of pk fields in the referenced object: > >>> > >>> <class-descriptor > >>> class="brj.ojb.Person" > >>> table="tabPerson" > >>> > > >>> <field-descriptor id="1" > >>> name="id" > >>> column="id" > >>> jdbc-type="INTEGER" > >>> primarykey="true" <<<< pk1 > >>> autoincrement="true" > >>> conversion="brj.ojb.TestFieldConversion" > >>> /> > >>> <field-descriptor id="2" > >>> name="vorname" > >>> column="vorname" > >>> jdbc-type="VARCHAR" > >>> /> > >>> <field-descriptor id="3" > >>> name="name" > >>> column="name" > >>> jdbc-type="VARCHAR" > >>> primarykey="true" <<<< pk2 > >>> /> > >>> ... > >>> <reference-descriptor > >>> name="partner" > >>> class-ref="brj.ojb.Person" > >>> proxy="true" > >>> > > >>> <foreignkey field-ref="idPartner"/> <<<< one fk ('name') is > >>> missing > >>> </reference-descriptor> > >>> > >>> hth > >>> jakob > >>> > >>> > >>> Janet Song wrote: > >>> > >>> > >>> > >>>> Hi, > >>>> > >>>> When i map compound or composite primary keys, i get an > >>>> ArrayOutOfBoundsException. Single primary key is fine. Appreciate > >>>> it if > >>>> someone could shed some light on this problem. Thanks! > >>>> > >>>> > >>>> [org.apache.ojb.broker.accesslayer.JdbcAccessImpl] ERROR: > >>>> PersistenceBrokerException during the execution of materializeObject: > >>>> > >>> > >> Could > >> > >> > >>>> not generate primary key values for given Identity > >>>> com.fedex.data.CorePieceCounterImpl{188119}, exception was > >>>> java.lang.ArrayIndexOutOfBoundsException: 1: 1 > >>>> Could not generate primary key values for given Identity > >>>> com.fedex.data.CorePieceCounterImpl{188119}, exception was > >>>> java.lang.ArrayIndexOutOfBoundsException: 1: 1 > >>>> java.lang.ArrayIndexOutOfBoundsException: 1 > >>>> at org.apache.ojb.broker.util.BrokerHelper.getKeyValues(Unknown > >>>> Source) > >>>> at org.apache.ojb.broker.util.BrokerHelper.getKeyValues(Unknown > >>>> Source) > >>>> at > >>>> org.apache.ojb.broker.accesslayer.StatementManager.getKeyValues(Unknown > >>>> > >>>> Source) > >>>> at > >>>> org.apache.ojb.broker.accesslayer.StatementManager.bindSelect(Unknown > >>>> Source) > >>>> at > >>>> > >>> > >>> org.apache.ojb.broker.accesslayer.JdbcAccessImpl.materializeObject(Unknown > >>> > >>> > >>>> Source) > >>>> at > >>>> org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getDBObject(Unknown > >>>> Source) > >>>> at > >>>> > >>> > >>> org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getObjectByIdentity(Un > >>> > >> > >> k > >> > >> > >>>> nown Source) > >>>> at > >>>> > >>> > >>> org.apache.ojb.broker.singlevm.DelegatingPersistenceBroker.getObjectByIdent > >>> > >> > >> i > >> > >> > >>>> ty(Unknown Source) > >>>> at > >>>> > >>> > >>> org.apache.ojb.broker.accesslayer.IndirectionHandler.materializeSubject(Unk > >>> > >> > >> n > >> > >> > >>>> own Source) > >>>> at > >>>> > >>> > >>> org.apache.ojb.broker.accesslayer.IndirectionHandler.getRealSubject(Unknown > >>> > >>> > >>>> Source) > >>>> at > >>>> org.apache.ojb.broker.accesslayer.IndirectionHandler.invoke(Unknown > >>>> > >>> > >> Source) > >> > >> > >>>> at $Proxy1.getSubmitFlag(Unknown Source) > >>>> at TestClient.testEqualCriteriaOneToOne(TestClient.java:104) > >>>> > >>>> > >>>> regards, > >>>> > >>>> Janet > >>>> > >>>> > >>>> > >>>> --------------------------------------------------------------------- > >>>> To unsubscribe, e-mail: [EMAIL PROTECTED] > >>>> For additional commands, e-mail: [EMAIL PROTECTED] > >>>> > >>>> > >>>> > >>>> > >>>> > >>> > >>> --------------------------------------------------------------------- > >>> To unsubscribe, e-mail: [EMAIL PROTECTED] > >>> For additional commands, e-mail: [EMAIL PROTECTED] > >>> > >>> > >>> > >> > >> > >> > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: [EMAIL PROTECTED] > >> For additional commands, e-mail: [EMAIL PROTECTED] > >> > >> > >> > >> > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]