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 7958105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:22:09+00:00 2026-06-04T04:22:09+00:00

I am using Spring + JPA + Hibernate + EntityManager to talk to the

  • 0

I am using Spring + JPA + Hibernate + EntityManager to talk to the database. I am getting ‘A JTA EntityManager cannot use getTransaction()‘ error. Please provide your insights and help me resolve the issue.

beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans default-autowire="byName"
    ... xmlns definitions...
      xsi:schemaLocation="...">

    <context:component-scan base-package="com.mycompany.myproject" />

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

    <bean id="myDAO" class="com.mycompany.myproject.dao.myDAO" />

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

    <tx:annotation-driven />
</beans>

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence ... xmlns definitions xsi:schemaLocation="..." version="1.0">
    <persistence-unit name="TEST_DS">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>java:/TEST_DS</jta-data-source>
        <class>com.twinspires.exchange.model.Test</class>
        <properties>
            <property name="hibernate.archive.autodetection" value="class, hbm" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
            <property name="hibernate.hbm2ddl.auto" value="validate" /> <!-- create-drop update -->
            <property name="hibernate.cache.use_query_cache" value="true" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider" />
              <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>             
        </properties>
    </persistence-unit>
</persistence>

Exception Stack Trace (Excerpt)

15:47:43,340 INFO  [STDOUT] DEBUG: org.springframework.transaction.annotation.AnnotationTransactionAttributeSource - Adding transactional method 'getName' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
15:47:43,343 INFO  [STDOUT] DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'transactionManager'
15:47:43,356 INFO  [STDOUT] DEBUG: org.springframework.orm.jpa.JpaTransactionManager - Creating new transaction with name [com.twinspires.exchange.dao.PicDAO.getName]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
15:47:44,114 INFO  [STDOUT] DEBUG: org.springframework.orm.jpa.JpaTransactionManager - Opened new EntityManager [org.hibernate.ejb.EntityManagerImpl@c629e5] for JPA transaction
15:47:44,124 INFO  [STDOUT] DEBUG: org.springframework.orm.jpa.JpaTransactionManager - Could not rollback EntityManager after failed transaction begin
15:47:44,125 INFO  [STDOUT] java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction()
15:47:44,125 INFO  [STDOUT]     at org.hibernate.ejb.AbstractEntityManagerImpl.getTransaction(AbstractEntityManagerImpl.java:818)
15:47:44,126 INFO  [STDOUT]     at org.springframework.orm.jpa.JpaTransactionManager.closeEntityManagerAfterFailedBegin(JpaTransactionManager.java:412)
15:47:44,127 INFO  [STDOUT]     at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:381)
15:47:44,128 INFO  [STDOUT]     at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
15:47:44,129 INFO  [STDOUT]     at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
15:47:44,129 INFO  [STDOUT]     at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
15:47:44,130 INFO  [STDOUT]     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
15:47:44,131 INFO  [STDOUT]     at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
15:47:44,131 INFO  [STDOUT]     at $Proxy175.getName(Unknown Source)

Folowing is my dao class:-

public class MyDao implements IMyDao {
      @PersistenceContext(unitName = "TEST_DS")
      private EntityManager entityManager;

      @Transactional
      public String getName() {            
            final Query query = entityManager.createQuery("from TestTable");
            final Object obj = query.getResultList().get(0);
            return obj == null ? "Empty" : (String) obj;
      }
}

Your help highly appreciated.

  • 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-04T04:22:10+00:00Added an answer on June 4, 2026 at 4:22 am

    Remove the jta-datasource from persitence.xml, configure datasource as a bean j2ee:jdni-lookup and inject it into the LocalContainerEntityManagerFactoryBean

    Remove this from persistence.xml

    <jta-data-source>java:/TEST_DS</jta-data-source>
    

    Configure the transaction-type to resource local

     <persistence-unit name="TEST_DS" transaction-type="RESOURCE_LOCAL">
    

    Change to your beans.xml

    <j2ee:jndi-lookup id="dataSource"  jndi-name="java:/TEST_DS"/>
    
     <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
       <property name="dataSource" ref="dataSource"/>
    </bean>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My web application is using Java, Hibernate's JPA implementation (EntityManager) and Spring. What are
I have developed demo application using spring struct and hibernate and getting following error
I am using Hibernate JPA and Spring with a Mysql database and I want
I am using Spring 3, JPA + Hibernate for a CMS application. In that
I'm doing a Web application using Spring 3.1.0.RELEASE, JSF 2.x, JPA 2 with Hibernate
I'm using Spring with Hibernate as a JPA provider and are trying to get
I am using Hibernate 3.6, JPA 2.0, and Spring 3.0.6. I have fields in
If I am using spring JPA, then should I use any ORM frameworks such
I'm using Spring + Hibernate + JPA and I have a situation where I
I'm using Hibernate JPA and Spring in my project. Suppose if I try to

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.