The transaction will be automatic if my simple example is modified to
be:

instantiate
populate

aLocation.addCD(aCD);
aLocation.save();

The OM/Peer classes save() method iterate through collections to save
everything within a transaction.  It is probably a bit confusing without
looking at the source, but using the addXXX methods then saving the top
most element saves everything within a transaction.  Using the setYYY
methods does not have this effect and you need to do as Leon showed to
get a transaction.

john mcnally   



Leon Messerschmidt wrote:
> 
> > instantiate
> > populate
> >
> > aCD.setLocation(aLocation);
> >
> > aLocation.save();
> > aCD.save();
> >
> > john mcnally
> >
> 
> Just my 2c.  This example is probably good enough, but if you're using a
> transactional db and it is important to you, for whatever reason, can do
> this:
> 
> DBConnection dbCon = BasePeer.beginTransaction()
> try
> {
>     aLocation.save(dbCon);
>     aCD.save(dbCon);
>     BasePeer.commitTransaction (dbCon);
> }
> catch (Exception e)
> {
>     Log.error (e);
>     BasePeer.rollbackTransaction (dbCon);
> }
> 
> ~ Leon
> 
> ---------------------------------------------------------------------
> 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]

Reply via email to