title: How can I configure glass fish to use application managed entity managers?
body: <p>How can I configure glass fish to use application managed entity managers? I get the following error with the configuration given below.</p>
  
  <p>I do not want glassfish to manage transactions, I want to only use spring managed transactions with RESOURCE_LOCAL setting, not JTA,  in the persistence unit</p>
  
  <pre><code>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.
  </code></pre>
  
  <p>My Cofiguration:</p>
  
  <pre><code>&lt;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"&gt;
    &lt;persistence-unit name="spring-jpa" transaction-type="RESOURCE_LOCAL"&gt;
      &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
      &lt;non-jta-data-source&gt;mysql/mydb&lt;/non-jta-data-source&gt;
      &lt;properties/&gt;
    &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>My Application context:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;
  
      &lt;context:component-scan base-package="com.myproject"/&gt;
      &lt;jpa:repositories base-package="com.myproject"/&gt;
      &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
      &lt;bean id="dataSource"
         //....
      &lt;/bean&gt;    
      &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource"/&gt;
          &lt;property name="persistenceUnitName" value="spring-jpa" /&gt;
          &lt;property name="jpaVendorAdapter"&gt;
            &lt;!--  &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;--&gt;
                  &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
                  &lt;property name="showSql" value="true" /&gt;
                  &lt;property name="generateDdl" value="true" /&gt;
                  &lt;property name="database" value="MYSQL" /&gt;
                  &lt;property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect"/&gt;
              &lt;/bean&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
  
  &lt;bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
    &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
  &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>