Hi Bart, Bart Molenkamp wrote:
I want to store a large graph of objects at once. To avoid getting referential integrity contraints violations (there are many references/collections in the tree, including parent/child relations), I first store a flat object, so it is known in the database (I do that for all objects that are new). Then I update all the objects with all their relationships. This way, I can't violate referential integrity. This does not work for all objects, e.g. those that have a foreign key in their primary key, but it works for my objects.
Did you try latest version from CVS (OJB_1_0_RELEASE branch), I add new extensions related to persistent object ordering in ODMG. Now it's possible to disable the automatic ordering in ODMG and to enable manual ordering also it's possible to flush objects without closing/committing the transaction (the default settings are set in OJB.properties, but it's possible to change these settings at runtime using TransactionExt[to change settings per tx] and ImplementationExt[to change the global settings], please see javadoc of these classes). I think with this methods it should be possible for you to handle the ordering and the writing to the DB by your own without extending/using internal OJB classes:
Implementation odmg = ... Database db = ... TransactionExt tx = (TransactionExt) odmg.newTransaction(); tx.setOrdering(false); tx.setNoteUserOrder(true); db.makePersistent(refObj); db.makePersistent(obj); tx.commit() OJB will insert: refObj, obj If you need to read a PK from an object first use flush: Implementation odmg = ... Database db = ... TransactionExt tx = (TransactionExt) odmg.newTransaction(); // not needed for this example //tx.setOrdering(false); //tx.setNoteUserOrder(true); db.makePersistent(refObj); tx.flush(); obj.setFK(refObj.getPK()); db.makePersistent(obj); tx.commit() hope it's useful.
I've solved it by extending TransactionImpl with my own imlpementation that stores flat objects before storing real objects. This seems to work good for me. But what about a get method for the envelope table on TransactionExt, or TransactionImpl? In that case, I don't have to extend TransactionImpl.
I don't have a problem in adding a public getter in TransactionImpl (will ASAP), but I don't want to make an official extension (in TransactionExt) to get access to ObjectEnvelopeTable, because in future versions of OJB (e.g. OJB1.1 or later) I want to encapsulate the persistent object state detection/handling in a separate service-api.
regards, Armin
Bart. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
