Hello all,

I am running into a strange update issue using OJBs. I am currently using
OJB 1.0.1. My DB setup is as follows:

TABLE A:
--------

CREATE TABLE A (
        A_ID INTEGER NOT NULL,
        B_ID INTEGER,
        X_ID INTEGER,
        Y_ID INTEGER,
        A_NAME VARCHAR (40),
        CONSTRAINT A_PK PRIMARY KEY (A_ID),
        CONSTRAINT A_FK1 FOREIGN KEY (B_ID, X_ID, Y_ID)
                         REFERENCES B (B_ID, X_ID, Y_ID) 
);

CREATE TABLE B (
        B_ID INTEGER INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY( START WITH 
1,
INCREMENT BY 1, NO CACHE),
        X_ID NOT NULL,
        Y_ID NOT NULL,
        B_NAME VARCHAR (40),
        CONSTRAINT B_PK PRIMARY KEY (B_ID, X_ID, Y_ID)
)

My java classes are as follows:

public class A {
        // actual columns
        private Integer aId;
        private Integer bId;
        private Integer xId;
        private Integer yId;
        private String  aName;
        
        // reference columns
        private B b;
}

public class B {
        // actual columns 
        private Integer bId;
        private Integer xId;
        private Integer yId;
        private String  bName;
        
        // reference columns
        private A a;
}

My reposityr.xml is set up as follows:

<jdbc-connection-descriptor 
        jcd-alias="OJBDb" 
        default-connection="true" 
        platform="Db2" 
        jdbc-level="1.0" 
        jndi-datasource-name="jdbc/ojbDataSource"
        username="uid" 
        password="pwd"  
        batch-mode="false" 
        useAutoCommit="0" 
        ignoreAutoCommitExceptions="false">
        <sequence-manager
className="org.apache.ojb.broker.util.sequence.SequenceManagerNativeImpl">
            <attribute attribute-name="grabSize" 
attribute-value="1"></attribute>
        </sequence-manager>
</jdbc-connection-descriptor>

<class-descriptor class="A" table="A">
        <field-descriptor name="aId" column="A_ID" primarykey="true"
jdbc-type="INTEGER" />
        <field-descriptor name="bId" column="b_ID" jdbc-type="INTEGER" />
        <field-descriptor name="xId" column="X_ID" jdbc-type="INTEGER" />
        <field-descriptor name="yId" column="Y_ID" jdbc-type="INTEGER" />
        <field-descriptor name="aName" column="A_NAME" jdbc-type="VARCHAR"
length="40" />
        <reference-descriptor name="b" class-ref="B">
                <foreignkey field-ref="bId" />
                <foreignkey field-ref="xId" />
                <foreignkey field-ref="yId" />
        </reference-descriptor>
</class-descriptor>

<class-descriptor class="B" table="B">
        <field-descriptor name="bId" column="B_ID" primarykey="true"
jdbc-type="INTEGER" autoincrement="true" access="readonly" />
        <field-descriptor name="xId" column="X_ID" primarykey="true"
jdbc-type="INTEGER" nullable="false" />
        <field-descriptor name="yId" column="Y_ID" primarykey="true"
jdbc-type="INTEGER" nullable="false" />
        <field-descriptor name="bName" column="B_NAME" jdbc-type="VARCHAR"
length="40" />
        <reference-descriptor name="a" class-ref="A">
                <foreignkey field-ref="bId" />
                <foreignkey field-ref="xId" />
                <foreignkey field-ref="yId" />
        </reference-descriptor>
</class-descriptor>

My java code to populate these tables goes like this:

PersistenceBroker broker =
PersistenceBrokerFactory.defaultPersistenceBroker();

Integer aId = //some Integer;
Integer xId = //some Integer;
Integer yId = //some Integer;


A a = new A();
a.setAId(aId);
a.setAName("aaa");

broker.clearCache();
broker.store(a);

B b = new B();

b.setXId(xId);
b.setYId(yId);
b.setBName("bbb");

broker.clearCache();
broker.store(b);

Integer bId = b.getBId();

a.setBId(bId);
a.setXId(xId);
a.setYId(yId);

broker.clearCache();
broker.store(a);

Per my understanding of OJBs, the second time I am storing object a, since
it's a reference to the 
existing row in DB, it will just update the DB with the new values.
However, it does not update 
those new values I insert into a the second time. However, if I take off
xId and yId as primary keys
from table b (and update the repositor.xml and code accordingly), they are
inserted. This makes me 
believe that the primary keys are causing some problem. Is my approach
correct in the first place?

Can I hold a reference to an object, update some values, and store it
again? I even tried creating a 
new reference to the object a before I called the store second time, but
it still does not work. 
What am I doing wrong?? Any help is grately appreciated. Thanks.

Regards,
-Vamsi

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to