Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 如何配置glass fish以使用应用程序管理的实体管理器?_Spring_Transactions_Glassfish - Fatal编程技术网

Spring 如何配置glass fish以使用应用程序管理的实体管理器?

Spring 如何配置glass fish以使用应用程序管理的实体管理器?,spring,transactions,glassfish,Spring,Transactions,Glassfish,如何配置glass fish以使用应用程序管理的实体管理器?我在下面给出的配置中遇到以下错误 我不希望glassfish管理事务,我只希望在持久化单元中使用带有RESOURCE_LOCAL设置的spring管理的事务,而不是JTA SEVERE: Exception while preparing the app : The persistence-context-ref-name [org.springframework.data.jpa.repository.support.JpaRepos

如何配置glass fish以使用应用程序管理的实体管理器?我在下面给出的配置中遇到以下错误

我不希望glassfish管理事务,我只希望在持久化单元中使用带有RESOURCE_LOCAL设置的spring管理的事务,而不是JTA

SEVERE: Exception while preparing the app : The persistence-context-ref-name [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean/entityManager] .... resolves to a persistence unit called [spring-jpa] which is of type RESOURCE_LOCAL. Only persistence units with transaction type JTA can be used as a container managed entity manager. Please verify your application.
我的共同形象:

<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  <persistence-unit name="spring-jpa" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <non-jta-data-source>mysql/mydb</non-jta-data-source>
    <properties/>
  </persistence-unit>
</persistence>

org.hibernate.ejb.HibernatePersistence
mysql/mydb
我的应用程序上下文:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xmlns:context="http://www.springframework.org/schema/context" 
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">

    <context:component-scan base-package="com.myproject"/>
    <jpa:repositories base-package="com.myproject"/>
    <tx:annotation-driven transaction-manager="transactionManager"/>
    <bean id="dataSource"
       //....
    </bean>    
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="persistenceUnitName" value="spring-jpa" />
        <property name="jpaVendorAdapter">
          <!--  <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">-->
                <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="true" />
                <property name="generateDdl" value="true" />
                <property name="database" value="MYSQL" />
                <property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect"/>
            </bean>
        </property>
    </bean>


<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

</beans>

我发现,我引用:

在JavaEE环境中,如果此元素[transaction type]不是 具体而言,默认值为JTA。在JavaSE环境中,如果 元素未指定,可假定默认为RESOURCE_LOCAL

因此,在您的配置中,请尝试:

<persistence-unit name="spring-jpa" transaction-type="JTA">