与Objectify和Appengine的春季交易

时间:2012-01-20 11:06:44

标签: spring google-app-engine transactions google-cloud-datastore objectify

我在Objectify中使用appengine来访问我的数据源。我使用Spring作为业务层。为了使用数据,我使用objectify-appengine-spring factory

我想使用基于注释的本地事务。您是否了解我可以直接作为spring bean插入的现有实现?

我真的想避免使用线程本地实现我自己的事务提供程序的痛苦。

2 个答案:

答案 0 :(得分:3)

检查LushLife的ObjectifyTransactionManager herehere

需要Spring XML配置(您可以找到它herehere):

<!-- ObjectifyManager -->
<bean id="objectifyManager" class="ex.objectify.spring.ObjectifyManager">
        <property name="basePackage" value="gso.model" />
</bean>

<!-- ObjectifyFactoryBean -->
<bean id="objectifyFactory" class="ex.objectify.spring.ObjectifyFactoryBean">
        <property name="manager" ref="objectifyManager" />
</bean>

<!-- Custom TransactionManager implementation -->
<bean id="transactionManager" class="ex.objectify.spring.ObjectifyTransactionManager">
        <property name="manager" ref="objectifyManager" />
</bean>

<!-- Necesary to enable use of @Transactional in your services -->
<tx:annotation-driven />

不要忘记使用@Transactional注释您的交易方法或类。

特别感谢这位project的作者。

答案 1 :(得分:0)

我猜这个解决方案只适用于Objectify3。

我可以在Spring AOP + Objectify4事务中使用事务属性(MANDATORY,REQUIRED等)的任何解决方案 - XML或Annotation?

此外,Objectify4的API文档仍然提到使用 ObjectifyFactory 方法 beginTransaction(),我认为这种方法不再可用。它给初学者带来了困惑。如果更新文档以反映最新行为,则会更有用。我希望我没有遗漏任何东西。

相关问题