Fab*_* B. 2 google-app-engine spring hibernate transactions
我的webapp(Spring3 + Hibernate3)总是使用@Transactional注释的服务类和这个配置:
<tx:annotation-driven transaction-manager="transactionManager" />
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="mySessionFactory" />
    </bean>
现在......我在Google AppEngine上.由于某些令人讨厌的原因,我还不知道,@ Transactal不起作用.它使用javax.naming中的某个类,该类未列入白名单.它最终得到:
创建名为'mySessionFactory'的bean时出错:FactoryBean对象的后处理失败; 嵌套异常是java.lang.SecurityException:无法获取类org.hibernate.impl.SessionFactoryImpl的成员
请不要问我为什么......: -
使用Spring的HibernateTemplate代替我的dao(使用原始会话工厂)解决了这个问题,但我知道它有点过时了.
所以,我想尝试使用手动旧式交易.问题:
SessionFactoryImpl依赖项不在Google App Engine白名单中.有很多谷歌点击它讨论它.
至于"做什么",你有选择:
依赖于另一个JPA提供商
根本不要使用ORM,并使用Spring的JdbcTemplate(我最喜欢的)原生
我不确定为什么你需要使用程序化事务管理,因为Hibernate是你问题的根源,但是如果你只是想知道如何,这里是草稿:
public class SomeService implements SomeInterface {
   private SomeDao thisDaoWrapsJdbcTemplate;
   private PlatformTransactionManager transactionManager;
   public void setTransactionManager( PlatformTransactionManager transactionManager ) {
      this.transactionManager = transactionManager;
   }
   public void doBusiness( Business: business ) {
      TransactionDefinition def = new DefaultTransactionDefinition();
      TransactionStatus status = transactionManager.getTransaction( def );
      try {
         // do business here
         Money money = Money.LOTS_OF
         ...
         // wire the money in..
         thisDaoWrapsJdbcTemplate.depositLotsOfMoney( money )
         transactionManager.commit( status );
      } catch ( DataAccessException dae ) {
         transactionManager.rollback( status );
         throw dae;
      }
      return;
   }
| 归档时间: | 
 | 
| 查看次数: | 6962 次 | 
| 最近记录: |