db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jakob Braeuchi <jbraeu...@gmx.ch>
Subject Re: Problems when using composite primary keys
Date Mon, 31 Mar 2003 17:27:26 GMT
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" <jbraeuchi@gmx.ch>
>To: "OJB Developers List" <ojb-dev@db.apache.org>
>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: ojb-dev-unsubscribe@db.apache.org
>>>For additional commands, e-mail: ojb-dev-help@db.apache.org
>>>
>>>
>>>
>>>
>>>      
>>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
>>For additional commands, e-mail: ojb-dev-help@db.apache.org
>>
>>
>>    
>>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
>For additional commands, e-mail: ojb-dev-help@db.apache.org
>
>
>  
>


Mime
View raw message