model.ConnectionBD.java Source code

Java tutorial

Introduction

Here is the source code for model.ConnectionBD.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

/**
 * Classe responsvel pela realizao da conexo com o banco de dados.
 *
 * @version 1.0
 * @author biancamoreira
 * @author Iago Rodrigues
 * @author Leylane Ferreira
 * @author Washington Filipe
 */
public class ConnectionBD {

    /**
     * Mtodo de abertura da conexo.
     * @return Session: sesso da conexo com o banco de dados.
     */
    public Session abrirConexao() {
        SessionFactory sf = HibernateUtil.getSessionFactory();
        Session session = sf.openSession();

        return session;

    }

    /**
     * Mtodo do fechamento da conexo com o banco de dados.
     * @param session Sesso a ser fechada.
     */

    public void fecharConexao(Session session) {
        session.close();
    }

    public static void main(String args[]) {
        SessionFactory sf = HibernateUtil.getSessionFactory();
        Session session = sf.openSession();

        sf.close();
    }

}