Why does the Hibernate 5.0.6 release package not contain a transaction bank?

I have a code like this:

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;

public class Main {

    public static void main(String[] args) {
        final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
                .configure().build();
        SessionFactory sessionFactory = null;
        try {
            sessionFactory = new MetadataSources(registry).buildMetadata()
                    .buildSessionFactory();
        } catch (Exception e) {
            StandardServiceRegistryBuilder.destroy(registry);
        }

        if (sessionFactory != null) {
            StudentInfo studentInfo = new StudentInfo();
            studentInfo.setRollNo(1);
            studentInfo.setName("Dmytro");

            Session session = sessionFactory.openSession();
            session.beginTransaction();

            session.save(studentInfo);

            session.getTransaction().commit();
            session.close();
            sessionFactory.close();
            StandardServiceRegistryBuilder.destroy(registry);
        }
    }
}

It throws an exception:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/transaction/SystemException
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:274)

I read that I have to add a jar of transaction APIs from the required folder in claspath. However, the Hibernate 5.0.6 release package does not contain it. enter image description here

Should I manually add the transaction API implementation?

+4
source share
3 answers

This seems to be the issue of Hibernate 5.0.6 release. There is no need to manually add transaction-api-1.1.jarfor the release of Hibernate 5.0.3.

To add the required jar

for maven

<dependency>
      <groupId>javax.transaction</groupId>
      <artifactId>jta</artifactId>
      <version>1.1</version>
</dependency>

for gradle build

compile group: 'javax.transaction', name: 'transaction-api', version: '1.1'

download user manual

http://central.maven.org/maven2/javax/transaction/transaction-api/1.1/transaction-api-1.1.jar

Update

, .

- JTA GAV, Hibernate, , , GAV. , , .

JTA ( )

2

. transaction-api-1.1.jar Hibernate 5.0.7.

Hibernate javax.transaction.Synchronization API. JTA , JTA Synchronization . , JTA spec jar . , : . HHH-10307

+2

v.ladynev. 5.0.3 java- API , 5.0.6 .

maven

Hibernate O/RM "5.0.3. : enter image description here

Hibernate O/RM "5.0.6. : enter image description here

It seems that the transaction API is not used in some applications, so if you need it, you can add it manually.

0
source

Source: https://habr.com/ru/post/1621949/


All Articles