Thread: [ojb-users] Re: Error in 1:n mapping using ODMG API
Brought to you by:
thma
From: Lorenzo N. <ln...@we...> - 2002-06-06 10:24:42
|
I hope this is not a FAQ :-) > From: "Govindarajan S (Gover)" <gov...@az...> > To: obj...@li... > Date: Wed, 5 Jun 2002 18:58:37 +0530 > Subject: [ojb-users] Error in 1:n mapping using ODMG API Hello, > 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 > [...] > 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, > [...] > At this stage an SQLException is thrown. > > What could be going wrong? why is it trying to insert the first > element again? I'm experiencing a similar problem, persinsting the classic 1:n mapping: 1 Order to n. tems (using OJB v.0.9) I made the association navigable in both directions: in Order there is a collection of Items AND in the Item there is the FK to Order + the reference to the Order Both tables PK are autoincrements. If I set the collection of Items in Order for auto-update, when I insert a new Order (with new Items), OJB tries to insert duplicate Items (with the same PK) causing the exception. Setting "auto-update" to false eliminates the problem! ( sadly, the auto-update feature could be useful :-( ) Here is the (very simplified) classes code: ---------------------------------------------------------- public class Order { private int id; private Vector items; [...] } public class Item { private int id; private int orderId; private Order order; [...] } ---------------------------------------------------------- And the (very simplified) mapping is this: ---------------------------------------------------------- <class-descriptor class="test.Order" table="_Orders"> <field-descriptor id="1" name="id" column="id" jdbc-type="INTEGER" primarykey="true" autoincrement="true" /> [...] <collection-descriptor name="items" element-class-ref="test.Item" auto-retrieve="true" auto-update="true" auto-delete="false" > <inverse-foreignkey field-id-ref="3"/> </collection-descriptor> </class-descriptor> <class-descriptor class="test.Item" table="_Items"> <field-descriptor id="1" name="id" column="id" jdbc-type="INTEGER" primarykey="true" autoincrement="true" /> [...] <field-descriptor id="3" name="orderId" column="orderId" jdbc-type="INTEGER" /> <reference-descriptor name="order" class-ref="test.Order" > <foreignkey field-id-ref="3"/> </reference-descriptor> </class-descriptor> ---------------------------------------------------------- [I removed fileds and references that doesn't have anything to do with the problem] THIS mapping will cause the problem inserting a new Order. Changing "auto-update" to "false", in the "collection-descriptor", will not. Is is an OJB problem? Or is it a logic problem in the mapping? Bye Lorenzo WEBPLAN srl v.Civerchio 4 20159 MILANO - ITALY tel. +39-02-69311782 fax. +39-02-60857392 |
From: Thomas M. <tho...@ho...> - 2002-06-06 17:16:23
|
Hi all, Lorenzo Nicora wrote: > I hope this is not a FAQ :-) > unfortunately it is! As mentioned in tutorial3.html#cascading YOU MUST NOT SET auto-update to true in an ODMG implementation. The ODMG has its own mechanism to do cascading operations! Thomas > >>From: "Govindarajan S (Gover)" <gov...@az...> >>To: obj...@li... >>Date: Wed, 5 Jun 2002 18:58:37 +0530 >>Subject: [ojb-users] Error in 1:n mapping using ODMG API >> > > Hello, > > >>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 >>[...] >> > >>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, >>[...] >>At this stage an SQLException is thrown. >> >>What could be going wrong? why is it trying to insert the first >>element again? >> > > > I'm experiencing a similar problem, persinsting the classic 1:n > mapping: 1 Order to n. tems > (using OJB v.0.9) > > I made the association navigable in both directions: > in Order there is a collection of Items AND in the Item there is the > FK to Order + the reference to the Order > Both tables PK are autoincrements. > > If I set the collection of Items in Order for auto-update, when I insert > a new Order (with new Items), OJB tries to insert duplicate Items > (with the same PK) causing the exception. > Setting "auto-update" to false eliminates the problem! ( sadly, the > auto-update feature could be useful :-( ) > > Here is the (very simplified) classes code: > ---------------------------------------------------------- > public class Order > { > private int id; > private Vector items; > [...] > } > > public class Item > { > private int id; > private int orderId; > private Order order; > [...] > } > ---------------------------------------------------------- > > And the (very simplified) mapping is this: > ---------------------------------------------------------- > <class-descriptor class="test.Order" table="_Orders"> > <field-descriptor id="1" > name="id" > column="id" > jdbc-type="INTEGER" > primarykey="true" > autoincrement="true" > /> > [...] > <collection-descriptor name="items" > element-class-ref="test.Item" > auto-retrieve="true" auto-update="true" auto-delete="false" > > > <inverse-foreignkey field-id-ref="3"/> > </collection-descriptor> > </class-descriptor> > > <class-descriptor class="test.Item" table="_Items"> > <field-descriptor id="1" > name="id" > column="id" > jdbc-type="INTEGER" > primarykey="true" > autoincrement="true" > /> > [...] > <field-descriptor id="3" > name="orderId" > column="orderId" > jdbc-type="INTEGER" > /> > <reference-descriptor name="order" > class-ref="test.Order" > > > <foreignkey field-id-ref="3"/> > </reference-descriptor> > </class-descriptor> > ---------------------------------------------------------- > [I removed fileds and references that doesn't have anything to do > with the problem] > > THIS mapping will cause the problem inserting a new Order. > Changing "auto-update" to "false", in the "collection-descriptor", will > not. > > Is is an OJB problem? > Or is it a logic problem in the mapping? > > Bye > Lorenzo > > > > > > > WEBPLAN srl > v.Civerchio 4 > 20159 MILANO - ITALY > tel. +39-02-69311782 > fax. +39-02-60857392 > > > > _______________________________________________________________ > > 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 > > > > |