db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Graham Leggett <minf...@sharp.fm>
Subject Re: Transactions and saving - problems with commit
Date Thu, 18 Sep 2003 16:01:25 GMT
Ashley Hayes wrote:

> think you need to get a DB connection to do the saving with...
> conn = Transaction.beginOptional("yourb DB name", true);
> // then save with the conn object
> contact.save(conn );
> company.setContact(contact);
> company.save(conn );
> Transaction.commit(conn);

This is exactly what I am doing, and as described below, it does not work.

This is because the primary key that should have been written by 
contact.save() is not being saved, but rather deferred until the commit, 
but then an exception is thrown on the company.save() to say that the 
primary key does not exist - thus the chicken and egg situation.

Set Transaction.beginOptional(bdName, true) to (dbName, false) and the 
problem (and the transaction support) goes away.


> -----Original Message-----
> From: Graham Leggett [mailto:minfrin@sharp.fm]
> Sent: 18 September 2003 16:46
> To: Turbine Torque Users List
> Subject: Transactions and saving - problems with commit
> Hi all,
> I have two Torque generated objects, the first is linked to the second 
> via a foreign key. When I save the objects, I do this:
> contact.save();
> company.setContact(contact);
> company.save();
> And this works fine - both objects are saved correctly, and as they are 
> new objects, Torque handles their primary keys.
> The trouble starts when the above three statements are saved in a 
> transaction. On the "company.save()" an exception is thrown because the 
> primary key for contact cannot be found in the database, and the 
> transaction support kicks in, rolling everything back.
> How do I get around this? It seems that supporting both primary keys and 
> rollback at the same time is a catch-22 situation - any ideas what I am 
> doing wrong?
> Regards,
> Graham

minfrin@sharp.fm		"There's a moon
					over Bourbon Street

To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org

View raw message