You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Christian Zumbiehl <cz...@legioninteractive.com.au> on 2003/04/11 02:54:17 UTC

JDO updates on 1:1 relationship

Hi ,

I am tryng to do updates on a simple Class that has got a reference to a
foreign class (on side relationship).
 I get Null pointer Exceptions systematically. :(

When I remove the reference , the update works .. 
I have noticed that all objects (Dates, Vectors ..) must be initialized in
the class constructor , but that is not enough for references ..

In case you have experienced something similar, here are the facts :

The Null pointer on Transaction.commit :
     [java] java.lang.NullPointerException
     [java]     at org.apache.ojb.jdori.sql.OjbStoreManager.fetch(Unknown
Source)
     [java]     at org.apache.ojb.jdori.sql.OjbStoreManager.update(Unknown
Source)
     [java]     at com.sun.jdori.common.state.PersistentDirty.flush(Unknown
Sour
...


my class (inspired from tutorial 5) :
public class Product implements Serializable {

	public String id;
	public String name;
            public java.util.Date dateLastUpdate;
    	public double price;
	public int stock;
/** Reference to foreign class */
           public Account account ;
           public String accountId;

	public Product() {
            dateLastUpdate = new java.util.Date();
          //  account = new Account();
	}
 }


the JDO xml :

 <class name="Product">
  <extension vendor-name="ojb" key="table" value="Product"/>

  <field name="id">
    <extension vendor-name="ojb" key="column" value="id"/>
   </field>
   <field name="name">
    <extension vendor-name="ojb" key="column" value="name"/>
   </field>
   <field name="price">
    <extension vendor-name="ojb" key="column" value="price"/>
   </field>
   <field name="stock">
    <extension vendor-name="ojb" key="column" value="stock"/>
	<extension vendor-name="ojb" key="jdbc-type" value="INTEGER"/>
   </field>
   
   <field name="account" persistence-modifier="persistent" >
     <extension vendor-name="ojb" key="column" value="account"/>
   </field>
   
    <field name="accountId">
    <extension vendor-name="ojb" key="column" value="accountId"/>
   </field>    
   
  </class>
 </package>
</jdo>


the repository :

   <class-descriptor
   	  class="Product"
   	  table="PRODUCT"
   >
      <field-descriptor
         name="id"
         column="ID"
         jdbc-type="VARCHAR"
         primarykey="true"
         autoincrement="false"
      />
      <field-descriptor
         name="name"
         column="NAME"
         jdbc-type="VARCHAR"
      />
      <field-descriptor
         name="price"
         column="PRICE"
         jdbc-type="DOUBLE"
      />
      <field-descriptor
         name="stock"
         column="STOCK"
         jdbc-type="INTEGER"
      />
      
      <field-descriptor name="accountId"
	 column="ACCOUNTREF"
	 jdbc-type="VARCHAR"
	/>

       <reference-descriptor name="account"
  	 class-ref="Account"
              proxy="true"
              refresh="true"
              auto-retrieve="true"
              auto-update="false"
              auto-delete="false" >
		 <foreignkey field-ref="accountId"/>
	 </reference-descriptor>
   </class-descriptor>



If I remove the Account field the the update on Product works ...

I am getting really desperate now , on the edge of despair ...
I you know anything about this problem , please help !

Thanks
Christian