Results 1 to 3 of 3

Thread: Why do I need to add jpaVendorAdapter into my EntityManagerFactory?

  1. #1
    Join Date
    Mar 2012
    Posts
    3

    Default 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 at 08:17 PM.

  2. #2

    Default

    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,

  3. #3
    Join Date
    Mar 2012
    Posts
    3

    Default

    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>

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •