org.hibernate.TransactionException: Unable to locate JTA UserTransaction

Shirishkumar Bari

I am writing my first example for Inserting Record using Hibernate Framework .

To start with I am trying to following instructions given at URL

You can see my code at GIT Hibernate Basic

When calling below piece of code

public Long saveEmployee(Employee emp){
    Session session = new Configuration().configure().buildSessionFactory().openSession();
    session.beginTransaction();
    Long id = (Long) session.save(emp);
    session.getTransaction().commit();
    session.close();
    return id;
}

hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <!-- Database connection settings -->
            <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
            <property name="connection.url">jdbc:mysql://localhost:3306/test</property>
            <property name="connection.username">root</property>
            <property name="connection.password">root123</property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">2</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">false</property>
        <!-- validate | update | create | create-drop -->
        <!-- validate: validate the schema, makes no changes to the database.
        update: update the schema.
        create: creates the schema, destroying previous data.
        create-drop: drop the schema at the end of the session. -->
        <property name="hbm2ddl.auto">validate</property>
 <!-- added as suggested in below answer-->            
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>

        <mapping resource="Employee.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

It throws org.hibernate.TransactionException: Unable to locate JTA UserTransaction

Details :

  • I am not deploying the application from any Application server I am running it as plan Java application.
  • I am using Hibernate 4.1

Is it neccessary to deploy it in Application Server ?

Whether we have to explicitly specify the JTAUsertransaction in Hibernate 4.1 version?

=============== Update ==============

With
hibernate.transaction.factory_class = org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory Solved this error and I can execute the program .

But I still wanted to know the reason why its not working when using org.hibernate.transaction.JTATransactionFactory

Shirishkumar Bari

When used hibernate.transaction.factory_class = org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory

Solved this error and I can execute the program.

I have deliberately posted it as an answer so it would be helpful for someone.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

org.hibernate.TransactionException: Unable to locate JTA UserTransaction

From Dev

org.hibernate.HibernateException: Unable to locate current JTA transaction

From Dev

org.hibernate.TransactionException: nested transactions not supported

From Dev

org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor

From Dev

bitronix- Unable to locate current JTA transaction

From Dev

bitronix- Unable to locate current JTA transaction

From Dev

NamingException: jta.UserTransaction

From Dev

Hibernate: Unable to access TransactionManager or UserTransaction to make physical transaction delegate

From Dev

Unable to access TransactionManager or UserTransaction after updating to Hibernate 5

From Dev

org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class

From Dev

Hibernate + Jersey + Jackson getting “org.hibernate.TransactionException: nested transactions not supported” randomly

From Dev

"org.hibernate.TransactionException: nested transactions not supported" but I didn't nest transactions

From Java

E: Unable to locate package mongodb-org

From Dev

hibernate: Unable to locate appropriate constructor on class - HQL

From Dev

org.openqa.selenium.NoSuchElementException: Unable to locate element

From Dev

Unable to locate element: org.openqa.selenium.NoSuchElementException

From Dev

Hibernate: Unable to locate persister: java.math.BigDecimal

From Dev

Hibernate: Unable to locate persister: java.math.BigDecimal

From Dev

Can I use Hibernate with JTA?

From Dev

java.lang.IllegalStateException: No JTA UserTransaction available. war deployment in jboss not working

From Dev

org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]

From Dev

Unable to resolve name [org.hibernate.dialect.MySQL5Dialect ] as strategy [org.hibernate.dialect.Dialect]

From Dev

org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]

From Dev

org.hibernate.internal.util.config.ConfigurationException: Could not locate cfg.xml resource [/HibernateTest/src/hibernate.cfg.xml]

From Dev

Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/tx]

From Dev

Where is the update site for `org.eclipse.fx.javafx` (Unable to locate installable unit)?

From Dev

Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/mvc

From Dev

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element

From Dev

Selenium Fluent Wait Implementation in the code still gives "org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element:"

Related Related

  1. 1

    org.hibernate.TransactionException: Unable to locate JTA UserTransaction

  2. 2

    org.hibernate.HibernateException: Unable to locate current JTA transaction

  3. 3

    org.hibernate.TransactionException: nested transactions not supported

  4. 4

    org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor

  5. 5

    bitronix- Unable to locate current JTA transaction

  6. 6

    bitronix- Unable to locate current JTA transaction

  7. 7

    NamingException: jta.UserTransaction

  8. 8

    Hibernate: Unable to access TransactionManager or UserTransaction to make physical transaction delegate

  9. 9

    Unable to access TransactionManager or UserTransaction after updating to Hibernate 5

  10. 10

    org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class

  11. 11

    Hibernate + Jersey + Jackson getting “org.hibernate.TransactionException: nested transactions not supported” randomly

  12. 12

    "org.hibernate.TransactionException: nested transactions not supported" but I didn't nest transactions

  13. 13

    E: Unable to locate package mongodb-org

  14. 14

    hibernate: Unable to locate appropriate constructor on class - HQL

  15. 15

    org.openqa.selenium.NoSuchElementException: Unable to locate element

  16. 16

    Unable to locate element: org.openqa.selenium.NoSuchElementException

  17. 17

    Hibernate: Unable to locate persister: java.math.BigDecimal

  18. 18

    Hibernate: Unable to locate persister: java.math.BigDecimal

  19. 19

    Can I use Hibernate with JTA?

  20. 20

    java.lang.IllegalStateException: No JTA UserTransaction available. war deployment in jboss not working

  21. 21

    org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]

  22. 22

    Unable to resolve name [org.hibernate.dialect.MySQL5Dialect ] as strategy [org.hibernate.dialect.Dialect]

  23. 23

    org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]

  24. 24

    org.hibernate.internal.util.config.ConfigurationException: Could not locate cfg.xml resource [/HibernateTest/src/hibernate.cfg.xml]

  25. 25

    Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/tx]

  26. 26

    Where is the update site for `org.eclipse.fx.javafx` (Unable to locate installable unit)?

  27. 27

    Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/mvc

  28. 28

    Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element

  29. 29

    Selenium Fluent Wait Implementation in the code still gives "org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element:"

HotTag

Archive