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.manages; import com.controller.AgentBean; import com.util.Agent; import com.util.HibernateUtil; import java.util.ArrayList; import java.util.List; import org.hibernate.Session; import org.hibernate.Transaction; /** * * @author user */ public class AgentManage { public void add1(AgentBean a) { Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); Agent aa = new Agent(); aa.setFirstName(a.getFirst_name()); aa.setLastName(a.getLast_name()); aa.setAddress(a.getAddress()); aa.setTelephone(a.getTelephone()); aa.setEmail(a.getEmail()); aa.setImportAmmount(a.getImport_ammount()); aa.setImportType(a.getImport_type()); session.save(aa); session.getTransaction().commit(); session.flush(); session.clear(); session.close(); } public static List<Agent> list() { Session session = HibernateUtil.getSessionFactory().openSession(); // return session.createQuery("SELECT firstName FROM Agent").list(); return session.createQuery("From Agent").list(); } public static List<Agent> getAllCustomers() { Session session = HibernateUtil.getSessionFactory().openSession(); /* try { trns = session.beginTransaction(); users = session.createQuery("SELECT firstName FROM Agent").list(); } catch (RuntimeException e) { e.printStackTrace(); } finally { session.flush(); session.close(); }*/ //return users; return session.createQuery("SELECT firstName FROM Agent").list(); } }