Hi Sean,

Sean Dockery wrote:

Still no recommendations? (I'm posting this through Gmane; can everyone on the mailing list read this?)


Sorry for the late reply, but I'm overwhelmed with posts and todo's.


Sean Dockery wrote:

No recommendations?

Sean Dockery wrote:

I have an application that uses the ODMG personality of OJB. I query objects and collections using PersistenceBroker Criteria; the PersistenceBroker is obtained from a Transaction object (via TransactionExt). Objects are stored via a tx.lock plus a tx.markDirty call. The application uses the default cache implementation.

My question is: What should I use as the initial value of a collection field in newly created business objects?

Consider the following simple class:

public class Category {

private Collection products;

    public Collection getProducts() {
        return products;
    }

    public void setProducts(Collection newProducts) {
        products = newProducts;
    }

}

When I create the Category object and store it in the cache, the next fetch retrieves that same Category object reference that was stored. The products field is null because it was never initialized.


What do you mean with 'create' - query for an Category or insert a new Category object?


Did you set auto-retrieve 'false' in your collection-descriptor for product? In that case call PB.retrieveAllReferences(...) on the main object to force loading of references (and cache object again if you
want the full materialized object cached)



You can use the 'refresh' attribute in the collection-descriptor to force loading of the collection on each main object request (this work for cached objects too) - need auto-retrieve 'true'


What value should I use when initializing the field? Can I use a plain old Collection of some sort (LinkedList, ArrayList, HashMap, et al) or are there some factory methods inside OJB from which I can obtain an instance of the default collection class.


You mean initialization on insert of main object? This will work with all Collection or ManageableCollection implementations.


One other thing: Because collection fields of objects retrieved from the database are typically of type RemovalAwareCollection, is it safe to replace the field value with a setProducts(plainOldList) or should I be modifying the collection via getProducts().add() and getProducts().remove()? Does it matter?

AFAIK RemovalAwareCollection was introduced to allow collection handling, in particular removal of collection objects on PB-level, in the same way as on odmg-level. So I would recommend the second 'modifying' way to go.




These two questions seem related (to me) by the fact that if I use a standard Collection subclass when I create an object and store it in the cache, it will never see a RemovalAwareCollection (for example) until the object has been purged from the cache and reloaded.


hmm, valid argument never think about this. In that case you can use PB.retrieveAllReferences(...)/retrieveReference(...) to re-assign the collection after insert or remove the object from cache after insert.


regards,
Armin



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