Sam,

Can you provide the exception trace?
I notice that you are adding user2 twice. This is no excuse for the DAS to not properly roll back the transaction, but it may be causing the exception in the first place.
Is there a chance you have specified that the DAS not manage transactions?

Thanks.
--
Kevin

Sam Su wrote:

Hi all, I would like to ask how to add two dataobjects in one transaction.
As depited in the tuscany user guide( refer to
http://wiki.apache.org/ws/WorkingWithTransactions):
when DAS applyChanges() method is called, the DAS will create a set of
INSERT/UPDATE and DELETE statments to flush the graph changes to the
database and all of these statements will be executed as part of a single
transaction. If the method returns without exception then the application
can assume that all changes were successfully committed to the database. If
an exception is returned then the changes will have all been rolled back.

However, the fact that my following code shows is not match with it.

/***********************code*******************************/
       List objs=new ArrayList();
       User user=UserFactory.INSTANCE.createUser();
       user.setUserId("3");
       user.setPassword("898989");
       user.setName("wo");
       user.setAvailable("1");

       User user2=UserFactory.INSTANCE.createUser();
       user2.setUserId("2");
       user2.setPassword("898989");
       user2.setName("wo");
       user2.setAvailable("1");
       objs.add(user2);

      objs.add(user);
      objs.add(user2);

           Connection conn = dataSource.getConnection();
           conn.setAutoCommit(false);
           DAS das = DAS.FACTORY.createDAS(new
ClassPathResource(schemaConfig).getInputStream(), conn);
           Command command = das.getCommand(commandName);
           DataObject root = command.executeQuery();
           if (logger.isDebugEnabled())
               logger.debug("dataobject collection to be insert:" +
objects.toString());
           for (int i = 0; i < objects.size(); i++)
               root.getList("User").addAll(objs);
           das.applyChanges(root);

user2 is fail to be inserted into database caused by a exception, and the
user1is inserted into database successfully but not rollback.




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to