[ojb-users] Storing mapped objects
Brought to you by:
thma
From: Govindarajan S (Gover) <gov...@az...> - 2002-05-31 05:40:28
|
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. 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. 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 . . . .). 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. But if OJB doesn't look in that Collection it seems inpossible to insert data in that table without implicit mapping for "association table"?? 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. 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 |