Thanks Armen, that worked. I've made this same mistake before, you would think I'd learn :)
The AdmObject will have many more extents in the full application. Every persistent class will extend it, or a subclass of it. I only had one class extending it in this subset. -----Original Message----- From: Armin Waibel [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 22, 2005 8:38 AM To: OJB Users List Subject: Re: Updating instead of Inserting Hi Wes, why did you need mapping for AdmObject when only one class "extent" AdmObject? In mapping for NCG <collection-descriptor name="subgroups" element-class-ref="model.client.Subgroup" auto-delete="true" auto-update="true" > <inverse-foreignkey field-ref="objectId" /> </collection-descriptor> the inverse-foreignkey refer to the PK field of SG. Think this is not correct, you need a FK field in SG to store the PK value of NCG. This FK field must also be used by the 'clientGroup' reference in SG [don't use an anomymous field, because of the 1:n relation http://db.apache.org/ojb/docu/guides/advanced-technique.html#How+do+ ] regards, Armin Lemke, Wesley wrote: > I have 4 classes: > > AdmObject -- highlevel class that all of our persistent classes > extend. Contains objectId field. Generic Group -- Abstract. Extends > AdmObject. Contains common fields for NewClientGroup and Subgroup and > the ojbConcreteClass. NewClientGroup -- extends Generic Group, > contains a collection of Subgroups. > Subgroup -- extends Generic Group. Has a reference to the > NewClientGroup. > > I am trying to persist NewClientGroup and Subgroup (along with common > fields in Generic Group) to the same table. Here is a portion of my > mapping document (most of the common fields from Generic group are > removed to simplifiy): > > <class-descriptor > class="model.AdmObject"> > <extent-class class-ref="model.client.GenericGroup" /> > </class-descriptor> > > <class-descriptor > class="model.client.GenericGroup"> > <extent-class class-ref="model.client.Subgroup" /> > <extent-class class-ref="model.client.NewClientGroup" /> > </class-descriptor> > > <class-descriptor > class="model.client.NewClientGroup" > table="client_group"> > <field-descriptor > name="objectId" > column="group_id" > jdbc-type="INTEGER" > primarykey="true" > autoincrement="true" > access="readonly" > /> > <field-descriptor > name="internalClientNumber" > column="INN_CLIENT_NB" > jdbc-type="VARCHAR" > /> > <field-descriptor > name="ojbConcreteClass" > column="CLASS_NAME" > jdbc-type="VARCHAR" > /> > <collection-descriptor > name="subgroups" > element-class-ref="model.client.Subgroup" > auto-delete="true" > auto-update="true" > > > <inverse-foreignkey field-ref="objectId" /> > </collection-descriptor> > </class-descriptor> > <class-descriptor > class="model.client.Subgroup" > table="client_group" > > > <field-descriptor > name="objectId" > column="group_id" > jdbc-type="INTEGER" > primarykey="true" > autoincrement="true" > access="readonly" > /> > <field-descriptor > name="name" > column="NAME" > jdbc-type="VARCHAR" > /> > <field-descriptor > name="ojbConcreteClass" > column="CLASS_NAME" > jdbc-type="VARCHAR" > /> > <reference-descriptor name="clientGroup" > class-ref="model.client.NewClientGroup"> > <foreignkey field-ref="objectId"/> > </reference-descriptor> > </class-descriptor> > > Here is the code I am using: > broker.beginTransaction(); > NewClientGroup ncg = new NewClientGroup(); > ncg.setInternalClientNumber("IntClntNbr"); > Subgroup sg = new Subgroup(); > sg.setName("FirstSubgroup"); > ncg.addSubgroup(sg); > Subgroup sg2 = new Subgroup(); > sg.setName("Second Subgroup"); > ncg.addSubgroup(sg2); > broker.store(ncg); > broker.commitTransaction(); > > I would assume that after the above code, there would be one > NewClientGroup and 2 Subgroups in my client_group table. However, > there is only one row, the Second Subgroup. Here is the debug SQL > generated: > > DEBUG: SQL:INSERT INTO client_group (INN_CLIENT_NB,CLASS_NAME) VALUES > (?,?) > DEBUG: SQL:UPDATE client_group SET NAME=?,CLASS_NAME=? WHERE group_id = > ? > > Am I doing something wrong with my mapping or code? Is it possible to > persist these classes to the same table? > > Any help would be appreciated. > > Thanks, > Wes > > --------------------------------------------------------------------- > 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]
