[ojb-users] Error in 1:n mapping using ODMG API
Brought to you by:
thma
From: Govindarajan S (Gover) <gov...@az...> - 2002-06-05 13:25:48
|
HI, I get the following exception when using the ODMG API for persisting the 1:n mapping. I have a product group class which has a collection of articles. Iam trying to persist the ProductGroup. As expected it tries to persist the Article as well. But during the process i get the following exception message, [ojb.broker.singlevm.PersistenceBrokerImpl] ERROR: Error in Transaction abort: General error: Warning: Some non-transactional changed tables couldn't be rolled back org.odmg.TransactionAbortedException: Invalid argument value: Duplicate entry '71' for key 1 at ojb.odmg.ObjectEnvelopeTable.commit(ObjectEnvelopeTable.java:116) at ojb.odmg.TransactionImpl.doCommit(TransactionImpl.java:200) at ojb.odmg.TransactionImpl.commit(TransactionImpl.java:350) at com.ojb.odmg.ProductDetailsClient.addArticleDetails(ProductDetailsClient.jav a:77) at com.ojb.odmg.ProductDetailsClient.main(ProductDetailsClient.java:49) Exception in thread "main" From what i observed its trying to insert the article, which is already inserted. I took a look at the SQL queries submitted to the database and found this, * INSERT INTO productgroup (prodGrpId,productGrpName,description) VALUES ('80','TestGrp','testgrp') * INSERT INTO article (articleId,articleName,prodGrpId) VALUES ('71','Art1','80') Inserted the first article whose id=71 * INSERT INTO article (articleId,articleName,prodGrpId) VALUES ('72','Art2','80') Inserted the second article whose id=72 * INSERT INTO article (articleId,articleName,prodGrpId) VALUES ('71','Art1','80') Fires a third insert with the same id=71 At this stage an SQLException is thrown. What could be going wrong? why is it trying to insert the first element again? Iam using the same repository.xml which i used for persisting using the PersistenceBroker API. The persistence code is below, try { ProductGroup prodGrp = new ProductGroup(); prodGrp.setProdGroupName("TestGrp"); prodGrp.setDescription ("testgrp"); Article art1 = new Article(); art1.setArticleName("Art1"); Article art2 = new Article(); art2.setArticleName("Art2"); prodGrp.addArticle (art1); prodGrp.addArticle (art2); Transaction tx = odmg.newTransaction(); tx.begin(); tx.lock (prodGrp,tx.WRITE); tx.commit(); } catch (PersistenceBrokerException pExp) { System.out.println ("----- Error persisting Article -----"); pExp.printStackTrace(); } // end of try-catch gover |