<commit_before>package com.vladmihalcea.book.hpjp.hibernate.connection.jta;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.support.TransactionTemplate;

import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = JTAConnectionReleaseConfiguration.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class JtaMultipleTransactionsTest {

    protected final Logger LOGGER = LoggerFactory.getLogger(getClass());

    @PersistenceUnit
    private EntityManagerFactory entityManagerFactory;

    @Autowired
    private TransactionTemplate transactionTemplate;

    @Test
    public void test() {

        try(Session session1 = entityManagerFactory.unwrap(SessionFactory.class).openSession()) {
            session1.beginTransaction();

            try(Session session2 = entityManagerFactory.unwrap(SessionFactory.class).openSession()) {
                session2.beginTransaction();
                session2.getTransaction().commit();

            }
            session1.getTransaction().commit();
        }
    }
}<commit_msg>no message<commit_after>package com.vladmihalcea.book.hpjp.hibernate.connection.jta;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;

import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = JTAConnectionReleaseConfiguration.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class JtaMultipleTransactionsTest {

    protected final Logger LOGGER = LoggerFactory.getLogger(getClass());

    @PersistenceUnit
    private EntityManagerFactory entityManagerFactory;

    @Autowired
    private TransactionTemplate transactionTemplate;

    @Test
    public void testManualTxManagement() {

        try(Session session1 = entityManagerFactory.unwrap(SessionFactory.class).openSession()) {
            session1.beginTransaction();

            try(Session session2 = entityManagerFactory.unwrap(SessionFactory.class).openSession()) {
                session2.beginTransaction();
                session2.getTransaction().commit();

            }
            session1.getTransaction().commit();
        }
    }

    @Test
    public void testAutoTxManagement() {

        transactionTemplate.execute((TransactionCallback<Void>) transactionStatus1 -> {
            try(Session session1 = entityManagerFactory.unwrap(SessionFactory.class).openSession()) {
                transactionTemplate.execute((TransactionCallback<Void>) transactionStatus2 -> {
                    try(Session session2 = entityManagerFactory.unwrap(SessionFactory.class).openSession()) {
                    }
                    return null;
                });
            }
            return null;
        });

    }
}
{'fraction_non_alphanumeric': 0.08851368636479919, 'fraction_numerical': 0.00665131747249936, 'mean_word_length': 4.117801047120419, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6208234', 'n_tokens_mistral': 993, 'n_tokens_neox': 969, 'n_words': 149}