Atomikos不与JPA的@TableGenerator合作 - 无法调用方法' commit'全局事务正在运行

时间:2017-05-06 05:14:34

标签: spring hibernate jpa spring-data atomikos

我有spring mvc应用程序。我已经成功配置了Atomikos,它适用于JMS,JDBC和一些JPA调用。

当我使用表生成器为主键插入实体时会出现问题。

    @Id
    @TableGenerator(name = "DOCUMENTGENERATOR", table = "om_sequence", pkColumnName = "sequence_name", pkColumnValue = "document_id", valueColumnName = "next_value")
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "DOCUMENTGENERATOR")
    @Column(name = "id", nullable = false)
    private Integer id;

这是日志

2017-05-06 07:50:10,937 DEBUG   127.0.0.1 [AtomikosConnectionProxy] atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@64280342: calling getAutoCommit... 
2017-05-06 07:50:10,937 DEBUG   127.0.0.1 [AtomikosConnectionProxy] atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@64280342: calling setAutoCommit(false)... 
Hibernate: 
    insert 
    into
        product
        (active, date_created, last_updated, created_by, updated_by, currency, description, drop_ship_end_user_only, drop_ship_only, end_user_only, height, internal_part_number, international_only, _length, list_price, manufacturer_id, not_quotable_internationally, obsolete, part_number, requires_prescription, requires_refrigeration, shelf_life, version, weight, weight_units, width, width_units) 
    values
        (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2017-05-06 07:50:11,059 DEBUG   127.0.0.1 [CompositeTransactionImp] addParticipant ( XAResourceTransaction: 3132372E302E312E312E746D313439343034363231303932383030303037:3132372E302E312E312E746D35 ) for transaction 127.0.1.1.tm149404621092800007 
2017-05-06 07:50:11,059 DEBUG   127.0.0.1 [XAResourceTransaction] XAResource.start ( 3132372E302E312E312E746D313439343034363231303932383030303037:3132372E302E312E312E746D35 , XAResource.TMNOFLAGS ) on resource XADS represented by XAResource instance com.mysql.jdbc.jdbc2.optional.JDBC4SuspendableXAConnection@42876db3 
2017-05-06 07:50:11,059 DEBUG   127.0.0.1 [CompositeTransactionImp] registerSynchronization ( com.atomikos.jdbc.AtomikosConnectionProxy$JdbcRequeueSynchronization@d4d29f1e ) for transaction 127.0.1.1.tm149404621092800007 
2017-05-06 07:50:11,059 DEBUG   127.0.0.1 [AtomikosConnectionProxy] atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@64280342: calling prepareStatement(insert into product (active, date_created, last_updated, created_by, updated_by, currency, description, drop_ship_end_user_only, drop_ship_only, end_user_only, height, internal_part_number, international_only, _length, list_price, manufacturer_id, not_quotable_internationally, obsolete, part_number, requires_prescription, requires_refrigeration, shelf_life, version, weight, weight_units, width, width_units) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?),1)... 
Hibernate: 
    insert 
    into
        packaging
        (active, date_created, last_updated, created_by, updated_by, parent_unit_of_packaging, product_id, unit_of_packaging, units) 
    values
        (?, ?, ?, ?, ?, ?, ?, ?, ?)
2017-05-06 07:50:11,144 DEBUG   127.0.0.1 [CompositeTransactionImp] registerSynchronization ( com.atomikos.jdbc.AtomikosConnectionProxy$JdbcRequeueSynchronization@d4d29f1e ) for transaction 127.0.1.1.tm149404621092800007 
2017-05-06 07:50:11,144 DEBUG   127.0.0.1 [AtomikosConnectionProxy] atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@64280342: calling prepareStatement(insert into packaging (active, date_created, last_updated, created_by, updated_by, parent_unit_of_packaging, product_id, unit_of_packaging, units) values (?, ?, ?, ?, ?, ?, ?, ?, ?),1)... 
Hibernate: 
    insert 
    into
        packaging
        (active, date_created, last_updated, created_by, updated_by, parent_unit_of_packaging, product_id, unit_of_packaging, units) 
    values
        (?, ?, ?, ?, ?, ?, ?, ?, ?)
2017-05-06 07:50:11,149 DEBUG   127.0.0.1 [CompositeTransactionImp] registerSynchronization ( com.atomikos.jdbc.AtomikosConnectionProxy$JdbcRequeueSynchronization@d4d29f1e ) for transaction 127.0.1.1.tm149404621092800007 
2017-05-06 07:50:11,149 DEBUG   127.0.0.1 [AtomikosConnectionProxy] atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@64280342: calling prepareStatement(insert into packaging (active, date_created, last_updated, created_by, updated_by, parent_unit_of_packaging, product_id, unit_of_packaging, units) values (?, ?, ?, ?, ?, ?, ?, ?, ?),1)... 
Hibernate: 
    insert 
    into
        packaging
        (active, date_created, last_updated, created_by, updated_by, parent_unit_of_packaging, product_id, unit_of_packaging, units) 
    values
        (?, ?, ?, ?, ?, ?, ?, ?, ?)
2017-05-06 07:50:11,152 DEBUG   127.0.0.1 [CompositeTransactionImp] registerSynchronization ( com.atomikos.jdbc.AtomikosConnectionProxy$JdbcRequeueSynchronization@d4d29f1e ) for transaction 127.0.1.1.tm149404621092800007 
2017-05-06 07:50:11,152 DEBUG   127.0.0.1 [AtomikosConnectionProxy] atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@64280342: calling prepareStatement(insert into packaging (active, date_created, last_updated, created_by, updated_by, parent_unit_of_packaging, product_id, unit_of_packaging, units) values (?, ?, ?, ?, ?, ?, ?, ?, ?),1)... 
product =..... 86813
2017-05-06 07:50:11,226 DEBUG   127.0.0.1 [AbstractDataSourceBean] AtomikosDataSoureBean 'XADS': getConnection()... 
2017-05-06 07:50:11,226 INFO    127.0.0.1 [AbstractDataSourceBean] AtomikosDataSoureBean 'XADS': init... 
2017-05-06 07:50:11,226 DEBUG   127.0.0.1 [AtomikosConnectionProxy] atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@339be81c: calling getAutoCommit... 
2017-05-06 07:50:11,226 DEBUG   127.0.0.1 [AtomikosConnectionProxy] atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@339be81c: calling setAutoCommit(false)... 
Hibernate: 
    select
        tbl.next_value 
    from
        om_sequence tbl 
    where
        tbl.sequence_name=? for update

2017-05-06 07:50:11,228 DEBUG   127.0.0.1 [CompositeTransactionImp] addParticipant ( XAResourceTransaction: 3132372E302E312E312E746D313439343034363231303932383030303037:3132372E302E312E312E746D36 ) for transaction 127.0.1.1.tm149404621092800007 
2017-05-06 07:50:11,228 DEBUG   127.0.0.1 [XAResourceTransaction] XAResource.start ( 3132372E302E312E312E746D313439343034363231303932383030303037:3132372E302E312E312E746D36 , XAResource.TMNOFLAGS ) on resource XADS represented by XAResource instance com.mysql.jdbc.jdbc2.optional.JDBC4SuspendableXAConnection@7f0abb9b 
2017-05-06 07:50:11,228 DEBUG   127.0.0.1 [CompositeTransactionImp] registerSynchronization ( com.atomikos.jdbc.AtomikosConnectionProxy$JdbcRequeueSynchronization@d4d29f1e ) for transaction 127.0.1.1.tm149404621092800007 
2017-05-06 07:50:11,228 DEBUG   127.0.0.1 [AtomikosConnectionProxy] atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@339be81c: calling prepareStatement(select tbl.next_value from om_sequence tbl where tbl.sequence_name=? for update)... 
Hibernate: 
    update
        om_sequence 
    set
        next_value=?  
    where
        next_value=? 
        and sequence_name=?
2017-05-06 07:50:11,229 DEBUG   127.0.0.1 [CompositeTransactionImp] registerSynchronization ( com.atomikos.jdbc.AtomikosConnectionProxy$JdbcRequeueSynchronization@d4d29f1e ) for transaction 127.0.1.1.tm149404621092800007 
2017-05-06 07:50:11,229 DEBUG   127.0.0.1 [AtomikosConnectionProxy] atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@339be81c: calling prepareStatement(update om_sequence set next_value=?  where next_value=? and sequence_name=?)... 
2017-05-06 07:50:11,230 WARN    127.0.0.1 [AtomikosSQLException] Cannot call method 'commit' while a global transaction is running 

报告错误"无法调用方法'提交'当全局交易正在运行时#34; - 在使用@TableGenerator插入任何实体之前出现

如何解决此问题?

编辑1:

这是实体管理器配置

 <!-- JPA EntityManagerFactory -->
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="persistenceUnitName" value="xPU"/>
        <property name="packagesToScan">
            <array>
                <value>a.b.c</value>
                <value>org.springframework.data.jpa.convert.threeten</value>
            </array>
        </property>
        <property name="jpaVendorAdapter" >
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="database"  value="MYSQL" />
            </bean>
        </property>
        <property name="jpaPropertyMap">
            <props>
                <prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate4.TransactionManagerLookup</prop> 
                <!--<prop key="javax.persistence.transactionType">JTA</prop>-->
                <!--<prop key="hibernate.transaction.jta.platform">com.atomikos.icatch.jta.hibernate4.AtomikosPlatform</prop>-->
                <!--<prop key="hibernate.search.autoregister_listeners">false</prop>-->
                <!--<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>-->
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
                <!--Cache setting--> 
                <prop key="hibernate.cache.use_second_level_cache">true</prop>
                <prop key="hibernate.cache.use_query_cache">true</prop>
                <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
                <prop key="hibernate.integration.envers.enabled">${hibernate.enableenvers}</prop>
            </props>
        </property>
        <property name="sharedCacheMode" value="ENABLE_SELECTIVE"/>
    </bean>

0 个答案:

没有答案