Re: [ojb-users] Storing mapped objects
Brought to you by:
thma
From: Thomas M. <tho...@ho...> - 2002-05-31 09:39:01
|
Hi all Govindarajan S (Gover) wrote: > HI, > Thanx for yr answer. While working through the tutorial:3 i found an > addition to the repository.xml which would do this persistence by > reachability. > <auto.retrieve>true</auto.retrieve> > <auto.update>false</auto.update> > <auto.delete>false</auto.delete> > Adding the above set of elements to your mapping would persist all dependent > objects aswell. > The OJB PersistenceBroker also provides persistence by reachability, sure. but use this feature in the PB API you'll have to change the above mentioned flags to <auto.retrieve>true</auto.retrieve> <auto.update>true</auto.update> <auto.delete>true</auto.delete> > I agree with your second observation aswell. Since there isnt a direct > mapping of the roles table in case of non-decomposed mapping, there are > cases when your mapping table is filled partially. Take the case of > PERSON_PROJECT, which has the > * PERSON_ID > * PROJECT_ID > * ROLE_NAME > With the non-decomposed mapping where u have mapped only the PERSON_ID and > PROJECT_ID in the ClassDescriptor mapping for PERSON and PROJECT when we try > to add a person who has a project associated with him, the ROLE_NAME field > is NULL and the Broker comes back with an error message as below, > > [DEFAULT] ERROR: 1, > Acme, > Acme Systems Inc., > int, > java.lang.String, > java.lang.String, > > this would probably have a wider implication. > > I havent looked at fully the ODMG spec, maybe that can help here. > > gover > > -----Original Message----- > From: Domagoj Jugovic [mailto:do...@la...] > Sent: Wednesday, May 29, 2002 7:16 PM > To: Govindarajan R S > Subject: Re: [ojb-users] Storing mapped objects > > > As I red the tutorials only ODMG implementation supports "persistence by > reachability" , so try with ODMG api. > That's not true! (see my statement above) > This leaves one question , OK, it's no problem to save the objects manualy, > but how to save data in "association table" in non-decomposed m:n mapping > (tutorial3 - Support for non-decomposed . . . .). OJB is doing this for you ! There are several testcases proving that this works! > In this case there is no concrete mapping for the "association table", so > OJB could only update that table by looking at new objects in Collection > specified by CollectionDescriptor. That's exactly what happens internally! > But if OJB doesn't look in that > Collection it seems inpossible to insert data in that table without > implicit mapping for "association table"?? Why do think OJB does not do this? Hey, this is an *open source* project. One short look at the source code of the respective testcases or stepping through the debugger will help you more than all these speculations! > Hi, > > I have a doubt regarding the storing of mapped objects. I tried to implement > the 1:1 relationship between the ProductGroup and Article. Whenever i was > setting the product instance in the article and when i persist the article > the ProductGroup is not persisted. Look at the code below, > > Article article = new Article(); > article.setArticleName ("TestArticle"); > > ProductGroup prodGrp = new ProductGroup(); > prodGrp.setProdGroupName("Group1"); > prodGrp.setDescription ("Testgroup"); > > article.setProductGroup (prodGrp); > try { > broker.beginTransaction(); > broker.store(article); > broker.commitTransaction(); > } catch (PersistenceBrokerException pExp) { > System.out.println ("----- Error persisting Article -----"); > pExp.printStackTrace(); > } // end of try-catch > > There are two tables namely the ProductGroup and Article. And the mapping is > all done as per the tutorial:3. > > With the above code, i expected the ProductGroup to be saved as well. But i > had to persist the ProductGroup object ('prodGrp') separately. Is this a bug > or iam missing out a funda here? > > This was the case with the 1:n mapping as well. you'll have to set <auto.update>true</auto.update> on the respective Reference- and CollectionDescriptors. It's explained here: http://objectbridge.sourceforge.net/tutorial3.html#cascading Again there is no need for "doubts". All those features are regression tested. HTH, Thomas > > I retrieve the ProductGroup and add articles to it. But i persist the > ProductGroup hoping that the objects in the collection are also persisted. > But i dont find the articles persisted. Code is below, > > Criteria qryCriteria = new Criteria(); > qryCriteria.addEqualTo ("prodGroupName","Grocery"); > QueryByCriteria criterion = new QueryByCriteria (ProductGroup.class, > qryCriteria); > ProductGroup prodGroup = (ProductGroup)broker. > getObjectByQuery(criterion); > Article art1 = new Article(); > art1.setArticleName ("Tea"); > art1.setProductGroup (prodGroup); > > Article art2 = new Article(); > art2.setArticleName ("Coffee"); > art2.setProductGroup (prodGroup); > > prodGroup.addArticle (art1); > prodGroup.addArticle (art2); > > try { > broker.beginTransaction(); > broker.store(prodGroup); > broker.commitTransaction(); > System.out.println("--- Added the articles ---"); > > } catch (PersistenceBrokerException pExp) { > System.out.println("---- Error storing 1:n relation objs ---"); > pExp.printStackTrace(); > } // end of try-catch > > any help in this regard would be greatly appreciated > > regds > > _______________________________________________________________ > > Don't miss the 2002 Sprint PCS Application Developer's Conference > August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm > > _______________________________________________ > Objectbridge-users mailing list > Obj...@li... > https://lists.sourceforge.net/lists/listinfo/objectbridge-users > > > > |