Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7777521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:09:49+00:00 2026-06-01T18:09:49+00:00

Well, my project was using EJB and JPA (with Hibernate), but I had to

  • 0

Well, my project was using EJB and JPA (with Hibernate), but I had to switch to Spring.
Everything was working well before that. The EJB used to inject the EntityManager, controled the transaction, etc.

Ok, when I switched to Spring, I had a lot of problems because I’m new on Spring. But after everything is running, I have the problem: the data is never saved on database. I configured my Spring to control the transactions, I have spring beans used in JSF, that has spring services that do the hard work. This services have a EntityManager injected and use @Transactional REQUIRED. This services pass the EntityManager to a DAO that call entityManager.persist(bean).

The selects appears to work well, the JTA transaction appears to work well to (I saw in log), but the entity is not saved!

Here is the log:

INFO: [Pronatec] - 04/04/2012 11:30:20 - [DEBUG] org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter: doFilterInternal() (linha 136): Opening JPA EntityManager in OpenEntityManagerInViewFilter

INFO: [Pronatec] - 04/04/2012 11:30:20 - [DEBUG] org.springframework.beans.factory.support.DefaultListableBeanFactory: doGetBean() (linha 245): Returning cached instance of singleton bean 'transactionManager'

INFO: [Pronatec] - 04/04/2012 11:30:20 - [DEBUG] org.springframework.orm.hibernate3.HibernateTransactionManager: getTransaction() (linha 365): Creating new transaction with name [br.org.cni.pronatec.controller.service.MontanteServiceImpl.adicionarValor]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''

INFO: [Pronatec] - 04/04/2012 11:30:20 - [DEBUG] org.springframework.orm.hibernate3.HibernateTransactionManager: doBegin() (linha 493): Opened new Session [org.hibernate.impl.SessionImpl@2b2fe2f0] for Hibernate transaction

INFO: [Pronatec] - 04/04/2012 11:30:20 - [DEBUG] org.springframework.orm.hibernate3.HibernateTransactionManager: doBegin() (linha 504): Preparing JDBC Connection of Hibernate Session [org.hibernate.impl.SessionImpl@2b2fe2f0]

INFO: [Pronatec] - 04/04/2012 11:30:20 - [DEBUG] org.springframework.orm.hibernate3.HibernateTransactionManager: doBegin() (linha 569): Exposing Hibernate transaction as JDBC transaction [com.sun.gjc.spi.jdbc40.ConnectionHolder40@3bcd4840]

INFO: [Pronatec] - 04/04/2012 11:30:20 - [DEBUG] org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler: doJoinTransaction() (linha 383): Joined JTA transaction


INFO: Hibernate: 
    select
        hibernate_sequence.nextval 
    from
        dual

INFO: [Pronatec] - 04/04/2012 11:30:20 - [DEBUG] org.springframework.orm.hibernate3.HibernateTransactionManager: processCommit() (linha 752): Initiating transaction commit

INFO: [Pronatec] - 04/04/2012 11:30:20 - [DEBUG] org.springframework.orm.hibernate3.HibernateTransactionManager: doCommit() (linha 652): Committing Hibernate transaction on Session [org.hibernate.impl.SessionImpl@2b2fe2f0]

INFO: [Pronatec] - 04/04/2012 11:30:20 - [DEBUG] org.springframework.orm.hibernate3.HibernateTransactionManager: doCleanupAfterCompletion() (linha 734): Closing Hibernate Session [org.hibernate.impl.SessionImpl@2b2fe2f0] after transaction

INFO: [Pronatec] - 04/04/2012 11:30:20 - [DEBUG] org.springframework.orm.hibernate3.SessionFactoryUtils: closeSession() (linha 800): Closing Hibernate Session

INFO: [Pronatec] - 04/04/2012 11:30:20 - [DEBUG] org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter: doFilterInternal() (linha 154): Closing JPA EntityManager in OpenEntityManagerInViewFilter

INFO: [Pronatec] - 04/04/2012 11:30:20 - [DEBUG] org.springframework.orm.jpa.EntityManagerFactoryUtils: closeEntityManager() (linha 343): Closing JPA EntityManager

In the log, I see it commiting the transaction, but I don’t see the insert query (the Hibernate is printing any query). I also see that the Hibernate lookup to get the next value of the sequence ID. But after that, it never really inserts.

Here is the spring context configuration:

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="PronatecPU" />
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
<property name="loadTimeWeaver">
    <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>
<property name="jpaProperties">
    <props>
    <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>
    </props>
</property>
</bean>


<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" >
    <property name="transactionManagerName" value="java:/TransactionManager" />
<property name="userTransactionName" value="UserTransaction" />
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />


<tx:annotation-driven transaction-manager="transactionManager" />

Here is my persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.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_1_0.xsd">
  <persistence-unit name="PronatecPU" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>jdbc/pronatec</jta-data-source>
    <class>br.org.cni.pronatec.model.bean.AgendamentoBuscaSistec</class>
    <class>br.org.cni.pronatec.model.bean.AgendamentoExportacaoZeus</class>
    <class>br.org.cni.pronatec.model.bean.AgendamentoImportacaoZeus</class>
    <class>br.org.cni.pronatec.model.bean.Aluno</class>
    <class>br.org.cni.pronatec.model.bean.Curso</class>
    <class>br.org.cni.pronatec.model.bean.DepartamentoRegional</class>
    <class>br.org.cni.pronatec.model.bean.Dof</class>
    <class>br.org.cni.pronatec.model.bean.Escola</class>
    <class>br.org.cni.pronatec.model.bean.Inconsistencia</class>
    <class>br.org.cni.pronatec.model.bean.Matricula</class>
    <class>br.org.cni.pronatec.model.bean.Montante</class>
    <class>br.org.cni.pronatec.model.bean.ParametrosVingentes</class>
    <class>br.org.cni.pronatec.model.bean.TipoCurso</class>
    <class>br.org.cni.pronatec.model.bean.Turma</class>
    <class>br.org.cni.pronatec.model.bean.UnidadeFederativa</class>
    <class>br.org.cni.pronatec.model.bean.ValorAssistenciaEstudantil</class>
    <class>br.org.cni.pronatec.model.bean.ValorHora</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
    <properties>
      <property name="current_session_context_class" value="thread"/>
      <property name="hibernate.show_sql" value="true"/>
      <property name="hibernate.format_sql" value="true"/>
      <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/>
      <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.SunONETransactionManagerLookup"/>
      <property name="hibernate.hbm2ddl.auto" value="update"/>
    </properties>
  </persistence-unit>
</persistence>

Here is my service that is injected in the managed bean:

@Service
@Scope("prototype")
@Transactional(propagation= Propagation.REQUIRED)
public class MontanteServiceImpl {
    // more code
    @PersistenceContext(unitName="PronatecPU", type= PersistenceContextType.EXTENDED)
    private EntityManager entityManager;
    // more code
    // The method that is called by another public method that do something before
    private void salvarMontante(Montante montante) {
        montante.setDataTransacao(new Date());

        MontanteDao montanteDao = new MontanteDao(entityManager);
        montanteDao.salvar(montante);
    }
    // more code
}

My MontanteDao inherits from a base DAO, like this:

public class MontanteDao extends BaseDao<Montante> {

    public MontanteDao(EntityManager entityManager) {
        super(entityManager);
    }

}

And the method that is called in BaseDao is this:

public void salvar(T bean) {
    entityManager.persist(bean);
}

Like you can see, it just pick the injected entityManager and call the persist() method. The transaction is being controlled by the Spring, like is printed in the log, but the insert query is never printed in log and it is never saved.

I’m sorry about my bad english.
Thanks in advance for who helps.

EDIT:
Debugging, I saw that after each entityManager.persist(T), there’s another action enqueued in the actionQueue of type “insert”. After all, it’s just queueing the actions and it’s never executing them. Have anyone already faced this kind of problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:09:50+00:00Added an answer on June 1, 2026 at 6:09 pm

    Well, I finally solved my problem. There was some misconfiguration of the JTA. I don’t know what could be, but I changed to RESOURCE_LOCAL and it worked.

    First time I tried RESOURCE_LOCAL, I fell in trouble with the Glassfish validating the @PersistenceContext annotation and throwing “Could not resolve a persistence unit corresponding to the persistence-context-ref-name[…]”. Then I found a good way to disable this validation: specifying

    metadata-complete=true
    

    on my web.xml. It says “Don’t look at the annotations, because it’s not necessary”. Well, Spring is my container and it’ll, by itself, look at annotations and configure what is needed. Then I don’t need my server to do so.

    After all, my configurations look like this:

    web.xml:

    <web-app version="3.0"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="
          http://java.sun.com/xml/ns/javaee
          http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
          metadata-complete="true">
    

    Spring’s context.xml:

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="PronatecPU" />
        <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
        <property name="loadTimeWeaver">
            <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
        </property>
        </bean>
    
        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" >
        <property name="entityManagerFactory" ref="entityManagerFactory" />
        </bean>
    
        <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    
        <tx:annotation-driven />
    

    persistence.xml:

    <persistence-unit name="PronatecPU" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <non-jta-data-source>jdbc/pronatec</non-jta-data-source>
        <!-- ... -->
    

    And my injected entityManager:

    @PersistenceContext(type= PersistenceContextType.EXTENDED)
    private EntityManager entityManager;
    

    I hope this will help who has the same problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using hibernate in my project and it is well going, but my
i am working on a wcf project everything went well before an attempt to
I have one project using NHibernate 1.2. I know it's old, but I've used
I just got off a small project using a WCF/REST Web Service that used
I'm working on my first PHP project, and it's going well. I've been able
My company is working on a development project using SQL Server 2008 Express. The
I am working on a c# project using ASP .net. I have a list
I'm creating a photo tagging project using mysql and php, that not only just
I am working on a project to take an existing project using JSF1.2, JSP,
I'm working on a web application project using ASP.NET MVC3 and database in SQL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.