<commit_before>package de.atomfrede.mate.domain.dao;

import javax.annotation.Resource;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import de.atomfrede.mate.domain.entities.AbstractEntity;
import de.atomfrede.mate.domain.entities.user.User;

@Repository
public abstract class AbstractDAO <EntityClass extends AbstractEntity> implements DAO<EntityClass>{

	@Resource
	protected SessionFactory sessionFactory;
	
	public Session getSession(){
		return sessionFactory.getCurrentSession();
	}
	
	public void persist(EntityClass entity) {
		getSession().saveOrUpdate(entity);
		getSession().flush();
    }
<commit_msg>AbstractDao opens a session if no session is currently available.<commit_after>package de.atomfrede.mate.domain.dao;

import javax.annotation.Resource;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import de.atomfrede.mate.domain.entities.AbstractEntity;
import de.atomfrede.mate.domain.entities.user.User;

@Repository
public abstract class AbstractDAO <EntityClass extends AbstractEntity> implements DAO<EntityClass>{

	@Resource
	protected SessionFactory sessionFactory;
	
	public Session getSession(){
		try{
			return sessionFactory.getCurrentSession();
		}catch(HibernateException he){
			return sessionFactory.openSession();
		}
	}
	
	public void persist(EntityClass entity) {
		getSession().saveOrUpdate(entity);
		getSession().flush();
    }

{'fraction_non_alphanumeric': 0.09407216494845361, 'fraction_numerical': 0.0, 'mean_word_length': 6.123853211009174, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5397460', 'n_tokens_mistral': 453, 'n_tokens_neox': 425, 'n_words': 94}