I removed the key generator from the reference class and
setAutoStore(false).  the app behaves as I wanted but the reference table
doesn't get updated.  It seems as though the cache gets updated

here is my code
    public void store(Object obj) {
        try {
            db = jdoBroker.obtainJDO().getDatabase();
            db.setAutoStore(false);
            db.begin();
            db.update(obj);
            db.commit();
            db.close();
        } catch (Throwable e) {
            e.printStackTrace();
        } finally {
            if (jdoBroker != null) jdoBroker.returnJDO();
        }
    } //store

    public Collection retrieve() {
        Object          obj;
        OQLQuery        oql;
        QueryResults    results = null;
        Collection      res = new ArrayList();

        try {
            db = jdoBroker.obtainJDO().getDatabase();
            db.begin();
            oql = db.getOQLQuery("SELECT b FROM " +
                                           entityClass.getName() + " b");
            results = oql.execute(Database.ReadOnly);
            while (results.hasMore()) {
                obj = results.next();
                res.add(obj);
            }
            db.commit();
            db.close();
        } catch (Throwable e) {
            e.printStackTrace();
        } finally {
            if (jdoBroker != null) jdoBroker.returnJDO();
        }
        return res;
    } //retrieve

/**
  *-- previous message thread:"JDO Mapping Problem"---*
  */
I have a situation where there is a list of pre-defined skills
in the SKILL table and each worker may have many skills, therefore
I have a collection of skill in the Worker class.

I am able to read & remove skills from the collection but when I
insert a skill in the collection, castor tries to Insert an new
record in the skill table as well as the workerskill table.

How do I get it to write only to the workerskill table?

Thank you.

<!-- Table: WORKER -->
      <class name="isman.base.person.Worker"
             extends="isman.base.person.Colleague"
             identity="key">

        <description>Person</description>
        <map-to table="WORKER" xml="Worker"/>
        <!-- +++++++++++++++++++++++++++++++++ -->

        <field name="key" type="integer" >
          <sql name="WORKERKEY" type="integer"/>
          <bind-xml node="attribute"/>
        </field>

        <field name="lastName" type="string" >
          <sql name="LASTNAME" type="varchar"/>
          <bind-xml node="attribute"/>
        </field>

        <!-- education File -->
        <field name="educationFile" type="isman.base.Education"
               collection="collection">
          <sql many-key="PARENTKEY"/>
          <bind-xml name="education" node="element"/>
        </field>

        <!-- employment history File -->
        <field name="historyFile" type="isman.base.WorkHistory"
               collection="collection">
          <sql many-key="PARENTKEY" />
          <bind-xml name="history" node="element"/>
        </field>

        <!-- SKILLS -->
        <field name="skills" type="isman.base.Skill"
               collection="collection">
          <sql many-table="WORKERSKILL" many-key="WORKERKEY"/>
          <bind-xml name="skills" node="element"/>
        </field>
      </class>

<!-- Table: SKILL -->
  <class name="isman.base.Skill"
         access="shared" identity="key">

    <description>Table with existing skills</description>
    <map-to table="SKILL" />

    <field name="key" type="integer" required="true">
      <sql name="SKILLKEY" type="integer" />
    </field>

    <field name="name" type="string">
      <sql name="NAME" type="varchar"/>
    </field>

    <field name="description" type="string">
      <sql name="DESCRIPTION" type="varchar"/>
    </field>

    <field name="workers" type="isman.base.person.Worker"
collection="collection"
    required="false">
    <sql many-table="WORKERSKILL" many-key="SKILLKEY" dirty="ignore"/>
    </field>

  </class>

the primary keys in the tables are as follows:

WORKER - workerkey
WORKERSKILL - workerkey, skillkey
SKILL - skillkey

-----Original Message-----
From: Toni Charlot [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, November 21, 2001 5:11 PM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] Castor behaves differently within JBoss


That's the same exactly problem I'm having and I'm not using JBOSS.  In fact
I posted this question under subject:"JDO Mapping Problem".

I'm using long transaction where I implement the TimeStampable interface.

I tried with autostore false and true but no cigar.  I'll try out a couple
of other things I read from this thread.

good luck to both of us.

-----Original Message-----
From: Jacek Kruszelnicki [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, November 21, 2001 4:39 PM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] Castor behaves differently within JBoss


I meant : old object = exists in the database

Here is the code snippet from my other post from a few minutes ago...
I only get exception (about duplicate objects) when trying to commit, not
sooner
(with autostore = true)

try {
t = new Test(70);
// company id=30 already exists in the DB, we just want to fetch it for
reference
Company co = (Company) pm.findByPrimaryKey(test.Company.class, new
Integer(30));
t.setOwnerCompany(co);
System.out.println("Co ++ " + co);
System.out.println("test " + t);
pm.create(t);
}
catch (Exception ex) {



-- Jacek


At 12:50 PM 11/21/2001 -0800, you wrote:
>See inline.
>
>
>
>-----Original Message-----
> >From: Jacek Kruszelnicki [mailto:[EMAIL PROTECTED]]
> >Sent: Thursday, 22 November 2001 9:14 a.m.
> >To: [EMAIL PROTECTED]
> >Subject: Re: [castor-dev] Castor behaves differently within JBoss
> >
> >
> >OK, for now I set autostore to false in the MBean configuration.
> >So I can now create a new object and refer it to an existing object -
ONLY
>
>The old object is not an existing object in the Castor world. It is only
>something outside the atmosphere.
>It is a mis-use. You should load the object again via Castor.
>Or, use long transaction update to made Castor aware of the out-of-space
>object.
>
>
>
>Thomas
>
>-----------------------------------------------------------
>If you wish to unsubscribe from this mailing, send mail to
>[EMAIL PROTECTED] with a subject of:
>         unsubscribe castor-dev

Jacek Kruszelnicki
Numatica Corporation
E-mail: [EMAIL PROTECTED]
Phone: (781) 756 8064

-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to