Announcement Announcement Module
Collapse
No announcement yet.
Jpa inserts not committing Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Jpa inserts not committing

    I'm using Spring 3.0.2.RELEASE with EclipseLink 2.0 and running inside of GlassFish 3. I'm building with Maven, although that shouldn't matter and running my unit tests with JUnit. I'm using a Dao patter that is leveraging the JpaTemplate by holding onto a reference of the JpaTemplate within my BaseDao and delegating all calls to it. My Unit Test is simple; insert 6 entities, but none appear in the database table. I've tried this with both a Derby in-memory database and a server instance of Derby. Both result in the same: no data being inserted. I can see EclipseLink being loaded and creating the database tables, so I know that there is connectivity to the database, but I can't seem to figure out why my inserts are not appearing.

    I've configured EclipseLink to log all statements, but I don't see the insert statements in the log file, which leads me to believe that they are actually not executing against the database.

    Below is my configuration:

    Base Dao:
    Code:
    public abstract class BaseDaoImpl<T, PK extends java.io.Serializable>
        implements BaseDao<T, PK> {
    
        protected JpaTemplate jpaTemplate;
    
     @PersistenceContext
        public void setEntityManager(EntityManager entityManager) {
            jpaTemplate = new JpaTemplate(entityManager);
        }
    
        @Override
        public void create(T entity) {
            getJpaTemplate().persist(entity);
        }
    My Spring configuration:
    Code:
        <context:annotation-config />
    
        <tx:annotation-driven/>
    
        <tx:jta-transaction-manager/>
    
        <jee:jndi-lookup id="myDataSource" jndi-name="jdbc/myDataSource"/>
        
    	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="entityManagerFactory" />
    		<property name="dataSource" ref="myDataSOurce"/>
    	</bean>
    
    	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
              <property name="jpaVendorAdapter">
                  <bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
                      <property name="showSql" value="true" />
                  </bean>
              </property>
              <property name="jpaDialect">
                  <bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" />
              </property>
              <property name="persistenceUnitName" value="my-pu"/>
    	</bean>
    persistence.xml
    Code:
    <persistence version="2.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_2_0.xsd">
      <persistence-unit name="my-pu" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/myDataSource</jta-data-source>
    
        <shared-cache-mode>ALL</shared-cache-mode>
    
        <properties>
          <property name="eclipselink.weaving" value="static" />
          <property name="eclipselink.ddl-generation" value="create-tables"/>
          <property name="eclipselink.logging.level" value="ALL"/>
          <property name="eclipselink.logging.exceptions" value="true" />
          <property name="eclipselink.jdbc.native-sql" value="true"/>
          <property name="eclipselink.jdbc.cache-statements" value="true"/>
          <property name="eclipselink.target-database" value="Auto"/>
          <property name="eclipselink.jdbc.exclusive-connection.mode" value="Transactional"/>
          <property name="eclipselink.logging.logger" value="ServerLogger"/>
          <property name="eclipselink.weaving" value="static"/>      
        </properties>
      </persistence-unit>
    </persistence>

    Thank you for the help...

  • #2
    I resolved it. It seems that I had two transaction managers defined that was causing some confusion as to which one was used.

    Code:
    <tx:jta-transaction-manager/>
    and

    Code:
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="entityManagerFactory" />
    		<property name="dataSource" ref="myDataSOurce"/>
    	</bean>
    Now I only need to figure out how to configure everything to work with JTA.

    Comment

    Working...
    X