model.ModelCombustivel.java Source code

Java tutorial

Introduction

Here is the source code for model.ModelCombustivel.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 DAO.DAOHibernateUtil;
import javax.swing.JOptionPane;
import org.hibernate.Session;

/**
 *
 * @author Ronai
 */
public class ModelCombustivel {

    public void insertCombustivel(Combustivel combustivel) {
        Session session = DAOHibernateUtil.getSessionFactory().getCurrentSession();

        try {
            session.beginTransaction();
            session.save(combustivel);
            session.getTransaction().commit();

        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
        }
    }

    public void updateCombustivel(Combustivel combustivel) {
        Session session = DAOHibernateUtil.getSessionFactory().getCurrentSession();

        session.beginTransaction();
        session.merge(combustivel);
        session.getTransaction().commit();
    }

    public void deleteCombustivel(Combustivel combustivel) {
        Session session = DAOHibernateUtil.getSessionFactory().getCurrentSession();

        session.beginTransaction();
        session.delete(combustivel);
        session.getTransaction().commit();
    }

}