谢谢大家,只能开启两个事务来解决啦。

在 2010年12月16日 下午6:11,kartik kudada <[email protected]>写道:

> If following operation throws an exception,we can not rollback the first
> transaction, because it is already committed. What I can think of right now
> is, you can manually delete it. but it is not the genuine solution.
>
> Why don't you create owned relation between these two table?
> Tell me about your thoughts?
>
> Regards,
> Kartik
>
> 2010/12/16 Liang Ding <[email protected]>
>
> Hi, kartik.
>> It works, but how can I rollback the 'first transaction' if the following
>> operations throws an exception?
>>
>> 2010/12/16 kartik kudada <[email protected]>
>>
>>> You can not operate on two entities in single transaction unless both are
>>> entity groups.
>>> First delete CityNum  in one transaction and then delete ScheduleProcess
>>>  in different transaction,
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> 2010/12/16 EtuO <[email protected]>
>>>
>>>> Caused by: java.lang.IllegalArgumentException: can't operate on
>>>>
>>>> multiple entity groups in a single transaction. found both Element {
>>>>  type: "CityNum"
>>>>  name: "013001"
>>>> }
>>>>  and Element {
>>>>  type: "ScheduleProcess"
>>>>  name: "013001"
>>>> }
>>>>
>>>>        at
>>>>
>>>> com.google.appengine.api.datastore.DatastoreApiHelper.translateError(DatastoreApiHelper.java:
>>>> 36)
>>>>        at com.google.appengine.api.datastore.DatastoreApiHelper
>>>> $1.convertException(DatastoreApiHelper.java:98)
>>>>        at
>>>> com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:
>>>> 69)
>>>>        at com.google.appengine.api.datastore.FutureHelper
>>>> $CumulativeAggregateFuture.get(FutureHelper.java:136)
>>>>        at com.google.appengine.api.datastore.FutureHelper
>>>> $TxnAwareFuture.get(FutureHelper.java:213)
>>>>        at
>>>> com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:
>>>> 67)
>>>>        at
>>>>
>>>> com.google.appengine.api.datastore.FutureHelper.getInternal(FutureHelper.java:
>>>> 71)
>>>>        at
>>>>
>>>> com.google.appengine.api.datastore.FutureHelper.quietGet(FutureHelper.java:
>>>> 58)
>>>>        at
>>>>
>>>> com.google.appengine.api.datastore.DatastoreServiceImpl.get(DatastoreServiceImpl.java:
>>>> 55)
>>>>        at
>>>>
>>>> org.datanucleus.store.appengine.RuntimeExceptionWrappingDatastoreService.get(RuntimeExceptionWrappingDatastoreService.java:
>>>> 64)
>>>>        ... 86 more
>>>>
>>>> 实现类代码:
>>>> /**
>>>>     * @see
>>>>
>>>> org.ertuo.taoplugin.facade.TransactionOperation#nestTrans(java.lang.Object[])
>>>>     */
>>>>    public void nestTrans(Object... objects) {
>>>>        String id = (String) objects[0];
>>>>        CityNum cn = cityNumDao.get(id);
>>>>        ScheduleProcess sp = scheduleDao.get(id);
>>>>        cityNumDao.delete(cn);
>>>>        scheduleDao.delete(sp);
>>>>        logger.info("id[" + id + "]对应的城市和任务删除完毕");
>>>>    }
>>>>
>>>> 接口代码:
>>>> /**
>>>>  * 事务性操作接口
>>>>  * @author mo.duanm
>>>>  * @version $Id: TransactionOperation.java, v 0.1 2010-12-16 下午
>>>> 05:22:23 mo.duanm Exp $
>>>>  */
>>>> public interface TransactionOperation {
>>>>
>>>>    /**
>>>>     * 嵌套事务
>>>>     * @param objects
>>>>     */
>>>>    @Transactional
>>>>    public void nestTrans(Object... objects);
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Google App Engine for Java" group.
>>>> To post to this group, send email to
>>>> [email protected].
>>>> To unsubscribe from this group, send email to
>>>> [email protected]<google-appengine-java%[email protected]>
>>>> .
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/google-appengine-java?hl=en.
>>>>
>>>>
>>>  --
>>> You received this message because you are subscribed to the Google Groups
>>> "Google App Engine for Java" group.
>>> To post to this group, send email to
>>> [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected]<google-appengine-java%[email protected]>
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/google-appengine-java?hl=en.
>>>
>>
>>
>>
>> --
>> My Blog: http://blog.csdn.net/DL88250
>> --------------------------------------------------------
>> Open Source, Open Mind, Open Sight, Open Future!
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Google App Engine for Java" group.
>> To post to this group, send email to
>> [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<google-appengine-java%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/google-appengine-java?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-appengine-java%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to