Java tutorial
/* * 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 com.onlineshopping.Models; import com.onlineshopping.POJO.OperatingSystem; import java.util.ArrayList; import java.util.List; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; /** * * @author Corncob */ public class OperatingSystemService { public static List<OperatingSystem> getOperatingSystemList() { List<OperatingSystem> list = new ArrayList<>(); SessionFactory factory = HibernateUtil.getSessionFactory(); Session session = factory.getCurrentSession(); Transaction tx = null; try { tx = session.getTransaction(); tx.begin(); list = session.createQuery("from OperatingSystem").list(); tx.commit(); } catch (Exception e) { if (tx != null) { tx.rollback(); } e.printStackTrace(); } return list; } }