Announcement Announcement Module
Collapse
No announcement yet.
Why do I need to add jpaVendorAdapter into my EntityManagerFactory? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why do I need to add jpaVendorAdapter into my EntityManagerFactory?

    I have a transaction that involves Spring JDBC template and JPA (actually Spring Data JPA). If I do not add jpaVendorAdapter into my entityManagerFactory, the transaction does not rollback both if something failed. From What transaction manager should I use for JBDC template When using JPA?, the solution is to ensure dataSource are the same. However, I found out besides this, jpaVendorAdapter is required.

    Why this is required? W/o it, what adapter was used?

    This is working.

    Code:
      <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="MyPersistenceUnit" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
        </property>
      </bean>
    This is NOT working.

    Code:
      <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="MyPersistenceUnit" />
      </bean>
    Sorry for cross-posting.
    Last edited by cklee75; Mar 29th, 2012, 09:17 PM.

  • #2
    You need to tell spring who the persistence provider is so that it can be used to create the EntityManagerFactory. If you are not specifying that via the JPAVendor adapter then it must be specified by setting an instance of the persistence provider or by specifying the persistence provider class to use or alternatively it must be spelled out in the persitence unit deployment descriptor. You have not posted your deployment descriptor so I can not see if you have done so but that would most likely be why it does not work.

    I will say that JPAVendorAdapter does seem to be the preferred approach these days and most examples you find will use this.

    Thanks,

    Comment


    • #3
      Here's my persistent provider on my container's persistence.xml. I have no issue to persist both JPA and JDBC operations, just rollback will not work w/o specifying JPAVendor adapter.

      Code:
          <persistence-unit name="MyPersistenceUnit" transaction-type="RESOURCE_LOCAL">
              <provider>org.hibernate.ejb.HibernatePersistence</provider>
              <non-jta-data-source>java:comp/env/jdbc/ooes_master</non-jta-data-source>
              <properties>
              	<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
              	<property name="hibernate.show_sql" value="true"/>
              	<property name="hibernate.hbm2ddl.auto" value="update"/>
                  <property name="hibernate.cache.region.factory_class" value="net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory"/>
                  <property name="hibernate.cache.use_second_level_cache" value="true"/>
                  <property name="hibernate.cache.use_query_cache" value="true"/>
              </properties>

      Comment

      Working...
      X