db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bogdan Daniliuc <bdanil...@montran.ro>
Subject Possible problem in CollectionProxyDefaultImpl
Date Thu, 01 Jul 2004 16:17:17 GMT
  Hi All,

  We are encountering a problem when using proxy with collections. We 
are usnig OJB 1.0 with PB API.

  Consider the following scenario: there is a class A that has a List of 
elements of type B (one-to-many relationship).

The mapping looks like:

  <class-descriptor class="test.A" table="A">
    <field-descriptor
        name="id"
        column="ID"
        autoincrement="true"
        primarykey="true"
        jdbc-type="BIGINT"
    />
...
    <collection-descriptor
        name="elements"
        element-class-ref="test.B"
        proxy="true"
        auto-update="true">
        <inverse-foreignkey field-ref="objectId"/>
    </collection-descriptor>
  </class-descriptor>

  Now assume that in the database there is an entry for A that has 
several associated B elements. In the code we do the

following:
    ...
    
    broker = PersistenceBrokerFactory.defaultPersistenceBroker();
    A bean = (A)broker.getObjectByQuery(q);

    broker.beginTransaction();
    List list = bean.getElements();
    list.clear();
    broker.store(bean);
    broker.commitTransaction();  
    ...

   With proxy="true" in the above descriptor, nothing happends when the 
above code is executed. If we set

proxy="false", all elements are deleted. The same thing (elemets are 
deleted) happends with proxy="true" and if we use

remove() on each element of the list instead of clear().  
   We tracked the problem in CollectionProxyDefaultImpl.clear(). More 
specifically, after the collection is cleared, a new collection is 
created and replaces tha original one. If we comment the code that 
replaces the collection, the behaviour is the same with proxy="true" and 
with proxy="false". However, in this case, the junit test 
testDeleteUnidirectional fails with foreign key violation exception.
   Is this a known problem?

   Regards,
 
   Bogdan Daniliuc

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message