RE: [OJB-developers] Clarification of Persistence Broker Storage
Brought to you by:
thma
From: Matthew B. <ma...@so...> - 2002-06-12 18:09:37
|
Great find! Post the test case to the list and I'll see what I can do, and put the test case in the suite to make sure we don't regress. There are not near enough proxy tests in there yet. Thanks again for the contribution. regards, Matthew -----Original Message----- From: Morgan Troke To: obj...@li... Sent: 6/12/02 11:03 AM Subject: [OJB-developers] Clarification of Persistence Broker Storage Hi, I have a few questions about the way in which the Persistence Broker stores objects that I was hoping could be cleared up. First, when storing an object which contains a collection (a 1:N mapping), it appears that even when proxies are used for the elements in the collection, when the object is stored each of the elements in the collection are materialized from the database. For example, within test.ojb.broker.PersistenceBrokerTest I have added the following test which retrieves a test.ojb.broker.ProductGroup and stores it again (all XML and .properties files have been left unmodified from the 0.9 release): public void testRetrieval() { try { ProductGroup pg = new ProductGroup(); pg.setId(8); Identity pgOID = new Identity(pg); pg = (ProductGroup) broker.getObjectByIdentity(pgOID); broker.store(pg); catch (Throwable t) { fail(t.getMessage()); } } When analyzing the SQL statements which are generated, it appears that all of the elements in the ProductGroup's collection are materialized when the broker.store(pg) line is executed. I traced through the code and tracked it to the calls to the logger, such as the one in store(Object obj) within ojb.broker.singlevm.PersistenceBrokerImpl.java: logger.debug("store " + obj); which calls the toString() method on the object being stored, in this case the ProductGroup, which returns the String values of all its fields. But since allArticlesInGroup is a Vector, this in turn calls toString() on each of the proxy elements in the collection, which then materializes all of the elements. This means that a potentially large number of calls to the DB are being made when objects with a collection are being stored. Is this behaviour intended, and if so is there anyway to modify it (perhaps in the XML files?) such that the calls to the DB are minimized? Second, when storing objects (again with PersistenceBroker), it appears that two calls to the DB are made - one to retrieve the object, and one to update it - regardless of whether or not the object has been modified. This has particular implications again with objects that contain collections. Using ProductGroup again as an example, when the elements of the collection have already been materialized (eg. by iterating over and calling a method on each of them), and the ProductGroup is stored, each of the elements in the collection is materialized (even though they already have been), and then updated. This results in a large number of calls to the DB being made when the ProductGroup is stored, even if nothing has been changed. In both of the above cases, have I used PersistenceBroker to retrieve and store objects correctly, as well as interpreted the calls made to the DB correctly? If so, is this behaviour intended and is there anyway to change it to minimize the number of calls made? Thanks in advace for any help, Morgan _______________________________________________________________ Sponsored by: ThinkGeek at http://www.ThinkGeek.com/ _______________________________________________ Objectbridge-developers mailing list Obj...@li... https://lists.sourceforge.net/lists/listinfo/objectbridge-developers |