Results 1 to 1 of 1

Thread: JPA never inserting Entities or Commiting DB Changes- Glassfish3, JPA2, Eclipselink

  1. #1
    Join Date
    Jan 2011
    Posts
    1

    Default JPA never inserting Entities or Commiting DB Changes- Glassfish3, JPA2, Eclipselink

    Apologies if this has been covered, I've been searching on this issue for a few days.

    The behavior I'm getting is that inserts to the MySQL db never occur for my entities, table generation occurs and eclipselink checks sequence values and increments/assigns them to the entity but never actually inserts to the db

    I've also noticed that after glassfish has shutdown the sequence table remain in the database but the user table does not. The updates to the sequence table do not remain either.

    I think it may be a transaction/spring issue that I am not handling correctly. Thoughts?

    peristence.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <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="reportPU">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
     
        <jta-data-source>jdbc/report</jta-data-source>
            <properties>
    <!--              <property name="eclipselink.target-server" value="SunAS9"/> -->
                <property name="eclipselink.target-database"  value="MySQL" />
                <property name="eclipselink.logging.level" value="FINEST"/>
                <property name="showSql" value="true" />
                <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
                <property name="eclipselink.ddl-generation.output-mode" value="database"/>
            </properties>
        </persistence-unit>
    </persistence>
    persistence-context.xml
    Code:
    <?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:jee="http://www.springframework.org/schema/jee"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    	http://www.springframework.org/schema/jee
    	http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
    
    
    	<bean id="emf" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
    	   <property name="persistenceUnitName" value="reportPU" /> 
    	</bean>
    	
    	<bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter" />
    			
    	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="emf" />	
    	</bean>
    	
    	<!-- enables injection of entity manager in spring -->	
    	<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    	
    </beans>
    user.java
    Code:
    @Entity
    public class User {
        
        public String getFirstName() {
            return firstName;
        }
        public void setFirstName(String firstName) {
            this.firstName = firstName;
        }
        public String getLastName() {
            return lastName;
        }
        public void setLastName(String lastName) {
            this.lastName = lastName;
        }
       
        @Id
        @GeneratedValue
        public int getId() {
            return id;
        }
        public void setId(int id) {
            this.id = id;
        }
       
        String firstName;
        String lastName;
        
        int id;
        
    }
    jpaUserDao.java
    Code:
    @Repository("userDao") // this is a component, gets picked up by the scan 
    @Transactional
    public class JpaUserDao implements UserDao {
        
        @PersistenceContext
        private EntityManager em;
    
        @Override
        public User getUserById(int id) {
            return em.find(User.class, id);
        }
        
        @Override
        public void addUser(User user) {
            em.persist(user);
        }
        
        @Override
        public void saveUser(User user) {
            em.merge(user);
        }
    }
    calling the user dao like this
    Code:
     
    u.User u = new User();
    u.setFirstName("please");
    u..setLastName("work");
    userDao.addUser(u);
    userDao.saveUser(u);
    Generates the following eclipselink activity in the glashfish server.log
    Code:
    client acquired
    
    PERSIST operation called on: com.model.User@150f4236.
    
    TX beginTransaction
    
    TX Internally starting
    
    external transaction has begun internally
    
    Execute query DataModifyQuery(sql="UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + #PREALLOC_SIZE WHERE SEQ_NAME = #SEQ_NAME")
    
    reconnecting to external connection pool
    
    UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?
    
    
    Execute query ValueReadQuery(sql="SELECT SEQ_COUNT FROM SEQUENCE WHERE SEQ_NAME = #SEQ_NAME")
    
    SELECT SEQ_COUNT FROM SEQUENCE WHERE SEQ_NAME = ?
    
    
    local sequencing preallocation for SEQ_GEN: objects: 50 
    
    TX commitTransaction
    
    TX Internally committing
    
    local sequencing preallocation is copied to preallocation after transaction commit
    
    external transaction has committed internally
    
    assign sequence to the object (1 -> com.mvc.model.User@150f4236)
    
    release unit of work
    
    client released
    
    here is user com.CCReport.mvc.model.User@150f4236
    
    client acquired
    
    Merge clone with references com.mvc.model.User@150f4236
    
    Execute query ReadObjectQuery(referenceClass=User )
    
    reconnecting to external connection pool
    
    SELECT ID
    
    
    release unit of work
    
    client released
    Last edited by durandal; Jan 30th, 2011 at 11:13 PM.

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
  •