After reviewing tutorial3 and the test cases a bit closer I have a few
questions. The collection-descriptor has the auto-update and auto-delete
attributes set to "true" but objects don't seem to be removed from the
collection after using the PersistenceBroker's store method on the
parent object. My collection is a java.util.List.

The tutorial lists three types of to implement 1 to many collections:
Arrays, users-defined collections and java.util.collection/list/vector.
Do all of these support removal of an on object from the collection or
must you use a user-defined a collection that implements
ManageableCollection as is done in the test case (OneToManyTest)?



-----Original Message-----
From: Jack Collins 
Sent: Wednesday, June 11, 2003 4:15 PM
To: OJB Users List
Subject: RE: Changing contents of a 1:n Collection Doesn't Seem to Work

Hi James - 

I apologize for the confusing example. I changed some of the names just
to make the example a little more clear but that only helps if you
change ALL the names :) (See #3 below)

1. I didn't think it was necessary to include a reference descriptor in
the child collection. Creating and storing seems to work OK without it.
I certainly don't need a reference back to the parent stored as a
property in the class of the child object.

2. Yes, the child pk (childID) is a foreign key.

3. <inverse-foreignkey field-ref="skuId"/> should be 
<inverse-foreignkey field-ref="parentId"/>

4. 
PersistenceBroker broker = null;
try {
  broker = PersistenceBrokerFactory.createPersistenceBroker(pbKey);

  broker.beginTransaction();


  // Must call retreiveAllReferences before 
  // adding children or they will be 
  // replaced by what is currently in the database.
  // References must be retreived or values will be null.

  broker.retrieveAllReferences(businessObject);
                        
  businessObject.setChildren(childVector);

  broker.store(businessObject);
  broker.commitTransaction();

} catch (Exception ex) {
  broker.abortTransaction();
  ex.printStackTrace();
  throw DatastoreException.datastoreError(ex);
} finally {
  try {
    broker.close();
  } catch (Exception ignored) {}
}


-----Original Message-----
From: James Nyika [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, June 11, 2003 3:35 PM
To: [EMAIL PROTECTED]
Subject: RE: Changing contents of a 1:n Collection Doesn't Seem to Work

Jack

 -so the reference descriptor is not necessary  in a 1-m ?
 ... you example below is a little confusing.

 -is the child pk a foreign key also ?
 -on the Sku object... what is skuId ? did you mean this to be the "id"
field ?
 
  also.. could you tell us what you do in code to actually add a Child
object to the Sku object.. even pseudo code would do.

j

James Nyika
Cambridge Technology Partners
The global eServices company of Novell, Inc.
http://www.novell.com

>>> [EMAIL PROTECTED] 6/11/2003 2:07:33 PM >>>
Thanks James & John -

Here is the section:

<class-descriptor class="c.w.b.m.Sku" table="SKU">
    <field-descriptor name="id" column="PARENT" jdbc-type="CHAR"
length="10" primarykey="true" nullable="false"/>
    <collection-descriptor element-class-ref="c.w.b.m.Child"
name="children" orderby="childId" refresh="true" auto-retrieve="true"
auto-update="true" auto-delete="true">
        <inverse-foreignkey field-ref="skuId"/>
    </collection-descriptor>
</class-descriptor>
<class-descriptor class="c.w.b.m.Child" table="Child">
    <field-descriptor name="parentId" jdbc-type="CHAR" column="PARENT"
primarykey="true" length="10" nullable="false"/>
    <field-descriptor name="childId" jdbc-type="INTEGER"
column="CHILDID" primarykey="true" nullable="false"/>
    <field-descriptor name="notes" jdbc-type="VARCHAR" column="NOTES"
length="255" nullable="true"/>
</class-descriptor>

-----Original Message-----
From: James Nyika [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, June 11, 2003 1:24 PM
To: [EMAIL PROTECTED] 
Subject: RE: Changing contents of a 1:n Collection Doesn't Seem to
Work

Hi All,

 Yeah.. need to see that repository_user.xml

 I have been having this problem for a while too.
 
 I noticed that:
  
  if auto-delete and auto-update are set:
  1. Creates always work fine.. if there are objects in the
collection,
then they are successfully created.
  2. If you search for the newly created object, get the collection,
add yet another new child object and attempt to store, it does not
work.
  3. Neither does doing the same in 2 except that you remove an
existing child

 However, having said that, the following does work

   1. Perform step 1 above.
   2. Create a new child object and call store() on it alone.
   3. Read the parent, object and voila! : it is magically in the
collection. 

 but this beats the whole point of using OJB. 

 below is MY repository_user.xml (notice- i do not have a
reference-descriptor in the child! do i need this ?)

thanks
------------------------------------------------------------------------
-----------------------------------------------------------------

------------------------------------------------------------descriptor
start-------------------------------------------------------------------
----
<class-descriptor
class="com.anasi.application.feecalculation.entities.OrderTO" 
table="ORDER">
<field-descriptor name="id" column="ID" jdbc-type="INTEGER"
conversion="org.apache.ojb.broker.accesslayer.conversions.Int2IntegerFie
ldConversion"
primarykey="true" autoincrement="true"/>
<field-descriptor name="orderState" column="ORDERSTATE"
jdbc-type="INTEGER"/>
<field-descriptor name="payerId" column="PAYER_ID"
jdbc-type="BIGINT"/>
<field-descriptor name="payeeId" column="PAYEE_ID"
jdbc-type="BIGINT"/>
<field-descriptor name="orderAmount" column="ORDERAMOUNT"
jdbc-type="DOUBLE" precision="5" scale="2"/>
<field-descriptor name="orderDate" column="ORDERDATE" jdbc-type="DATE"
conversion="org.apache.ojb.broker.accesslayer.conversions.JavaDate2SqlDa
teFieldConversion"/>
 <collection-descriptor name="adjustments"
element-class-ref="com.anasi.application.feecalculation.entities.Adjustm
entTO"
orderby="entryDate" sort="DESC" auto-retrieve="true"
auto-update="true"
auto-delete="true" refresh="true" >
         <inverse-foreignkey field-ref="orderId"/>
</collection-descriptor>
</class-descriptor>
 <class-descriptor
class="com.anasi.application.feecalculation.entities.AdjustmentTO" 
table="ADJUSTMENT">
  <field-descriptor name="id" column="ID" jdbc-type="INTEGER"
conversion="org.apache.ojb.broker.accesslayer.conversions.Int2IntegerFie
ldConversion"
primarykey="true" autoincrement="true"/>
      <field-descriptor name="reasonId" column="REASON_ID"
jdbc-type="BIGINT"/>
      <field-descriptor name="orderId" column="ORDER_ID"
jdbc-type="INTEGER"/>
      <field-descriptor name="typeId" column="TYPE_ID"
jdbc-type="BIGINT"/>
      <field-descriptor name="authCodeId" column="AUTH_CODE_ID"
jdbc-type="BIGINT"/>
      <field-descriptor name="amount" column="AMOUNT"
jdbc-type="DOUBLE" scale="2"/>
      <field-descriptor name="entryDate" column="ENTRY_DATE"
jdbc-type="DATE"
conversion="org.apache.ojb.broker.accesslayer.conversions.JavaDate2SqlDa
teFieldConversion"/>
      <field-descriptor name="effectiveDate" column="EFFECTIVE_DATE"
jdbc-type="DATE"
conversion="org.apache.ojb.broker.accesslayer.conversions.JavaDate2SqlDa
teFieldConversion"/>
      <field-descriptor name="expirationDate" column="EXPIRATION_DATE"
jdbc-type="DATE"
conversion="org.apache.ojb.broker.accesslayer.conversions.JavaDate2SqlDa
teFieldConversion"/>
  </class-descriptor>
------------------------------------------------------------descriptor
end---------------------------------------------------------------------
--



James Nyika
Cambridge Technology Partners
The global eServices company of Novell, Inc.
http://www.novell.com 

>>> [EMAIL PROTECTED] 6/11/2003 12:33:33 PM >>>
post your repository_user.xml

 do you have auto-delete=true and auto-update= true on your
collection-descriptor?


-----Original Message-----
From: Jack Collins [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, June 11, 2003 11:29 AM
To: [EMAIL PROTECTED] 
Subject: Changing contents of a 1:n Collection Doesn't Seem to Work


I have an object that has a collection as one of its properties. I can
create the object, add members to the collection and save it with no
problem. If I check the contents of the database I see the parent
object
and all of its children. If I retrieve that same object and remove one
of the child objects in the collection and save the parent again, the
changes to the collection are not reflected in the database. It seems
like OJB is only capable of adding to the contents of a collection but
not removing them. 
 
When I turned on the logging of the SqlGeneratorDefaultImpl I can see
insert and update statements, but never a delete statement to handle
the
removal of the child from the collection. 
 
I am using RC3 and have tried using a few different cache
implementations (ObjectCachePerBrokerImpl, ObjectCacheDefaultImpl,
ObjectCacheEmptyImpl) but always get the same result. 
 
What am I missing?
 

---------------------------------------------------------------------
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] 


---------------------------------------------------------------------
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]

Reply via email to