-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Entity not persisting into Database after persist()
PostPosted: Mon May 09, 2011 11:58 am 
Newbie

Joined: Mon May 09, 2011 11:50 am
Posts: 8
Hi,

I'm trying to setup my generic JPA DAO which seems to be working fine it does get primary key value and throws no exception. However, in the log I don't find any SQL INSERT statement and also the record is not being inserted.

persist method from generic dao:
Code:
   @Transactional(propagation = Propagation.REQUIRED)
   public void persist(T entity) {
      entityManager.persist(entity);
   }


Here is how entity manager is configured in spring.
Code:
   <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
      <property name="dataSource" ref="dataSource" />
      <property name="jpaVendorAdapter">
         <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="database" value="ORACLE" />
            <property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect" />
            <property name="generateDdl" value="true" />
            <property name="showSql" value="true" />
         </bean>
      </property>
      <property name="persistenceUnitName" value="travelRequestPersistenUnit"/>
   </bean>

   <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
      <property name="entityManagerFactory" ref="entityManagerFactory" />
      <property name="jpaDialect">
         <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
      </property>
   </bean>


See log below:

Code:
DEBUG com.spring.hibernate.jpa.CustomerFileService - Befor persisting file it has - Customer [Id=null, fileName=Test Application File, contentType=text/html, file=null]
DEBUG com.spring.hibernate.jpa.CustomerFileService - File service is calling file dao....
DEBUG org.hibernate.impl.SessionImpl - opened session at timestamp: 5345098932588544
DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG org.hibernate.jdbc.ConnectionManager - opening JDBC connection
DEBUG org.hibernate.SQL - select hibernate_sequence.nextval from dual
DEBUG org.hibernate.id.SequenceGenerator - Sequence identifier generated: 3
DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG org.hibernate.jdbc.ConnectionManager - aggressively releasing JDBC connection
DEBUG org.hibernate.jdbc.ConnectionManager - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
DEBUG org.hibernate.event.def.AbstractSaveEventListener - generated identifier: 3, using strategy: org.hibernate.id.SequenceGenerator
DEBUG com.spring.hibernate.jpa.CustomerFileService - DAO call to persists completed....
DEBUG com.spring.hibernate.jpa.CustomerFileService - After persisting file it has - Customer [Id=3, fileName=Test Application File, contentType=text/html, file=null]



Any help or pointers are much appreciated???


Top
 Profile  
 
 Post subject: Re: Entity not persisting into Database after persist()
PostPosted: Mon May 09, 2011 12:18 pm 
Newbie

Joined: Mon May 09, 2011 11:50 am
Posts: 8
update: adding entityManager.flush() throws "no transaction" exception.

Code:
   @Transactional(propagation = Propagation.REQUIRED)
   public void persist(T entity) {
      entityManager.persist(entity);
      entityManager.flush();
   }

Caused by: javax.persistence.TransactionRequiredException: no transaction is in progress
   at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:301)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)



Top
 Profile  
 
 Post subject: Re: Entity not persisting into Database after persist()
PostPosted: Mon May 09, 2011 2:58 pm 
Newbie

Joined: Mon May 09, 2011 11:50 am
Posts: 8
I was able to resolve the issue.


tiger.spring wrote:
update: adding entityManager.flush() throws "no transaction" exception.

Code:
   @Transactional(propagation = Propagation.REQUIRED)
   public void persist(T entity) {
      entityManager.persist(entity);
      entityManager.flush();
   }

Caused by: javax.persistence.TransactionRequiredException: no transaction is in progress
   at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:301)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)



Top
 Profile  
 
 Post subject: Re: Entity not persisting into Database after persist()
PostPosted: Tue Apr 09, 2013 8:42 pm 
Newbie

Joined: Tue Apr 09, 2013 8:38 pm
Posts: 1
Can you brief the exact solution that resolved the issue for you? I am having exact similar issue.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.