You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Sebastian <no...@gmx.net> on 2004/10/21 13:01:36 UTC

OTM Transaction Rollback broken?

Hi,
I'm using OJB 1.01 with MySQL (com.mysql.jdbc.Driver, 
useAutoCommit="2"). I'm trying to persist an object that contains a 
RemovalAwareCollection with persistable child objects (refresh="true", 
auto-retrieve="true", otm-dependent="true").

I added a PBLifeCycleListener to the OTM connection. In the BeforeInsert 
methods I'm validating the properties of the persistable object and 
throw a PersistenceBrokerException when certain object's properties are 
out of the valid range.

For testing purpose I set a property of one of the child objects to an 
invalid value and tried to persist the parent object:

Entity entity = new Entity();

// ... add child elements here and set a property of one
// child element to an invalid value

Transaction tx = otm.getTransaction(conn);
try
{
   tx.begin();
   conn.makePersistent(entity);
   tx.commit();
}
catch (PersistenceBrokerException e)
{
   if (tx.isInProgress()) tx.rollback();
}

I expect that when the PersistenceBrokerException is thrown and the 
tx.rollback() method is executed, neither the entity object nor its 
child objects are persisted to the database.
But after the tx.rollback() was executed all objects (except the one 
with the invalid property) have been persisted to the database.

Do I misunderstand the transaction concept or is it bug?


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


Re: OTM Transaction Rollback broken?

Posted by Sebastian <no...@gmx.net>.
Sebastian wrote:
> Hi,
> I'm using OJB 1.01 with MySQL (com.mysql.jdbc.Driver, 
> useAutoCommit="2"). I'm trying to persist an object that contains a 
> RemovalAwareCollection with persistable child objects (refresh="true", 
> auto-retrieve="true", otm-dependent="true").
> 
> I added a PBLifeCycleListener to the OTM connection. In the BeforeInsert 
> methods I'm validating the properties of the persistable object and 
> throw a PersistenceBrokerException when certain object's properties are 
> out of the valid range.
> 
> For testing purpose I set a property of one of the child objects to an 
> invalid value and tried to persist the parent object:
> 
> Entity entity = new Entity();
> 
> // ... add child elements here and set a property of one
> // child element to an invalid value
> 
> Transaction tx = otm.getTransaction(conn);
> try
> {
>   tx.begin();
>   conn.makePersistent(entity);
>   tx.commit();
> }
> catch (PersistenceBrokerException e)
> {
>   if (tx.isInProgress()) tx.rollback();
> }
> 
> I expect that when the PersistenceBrokerException is thrown and the 
> tx.rollback() method is executed, neither the entity object nor its 
> child objects are persisted to the database.
> But after the tx.rollback() was executed all objects (except the one 
> with the invalid property) have been persisted to the database.
> 
> Do I misunderstand the transaction concept or is it bug?

Changing the table type in mysql from myISAM to innoDB solved it.


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