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.micromap.dao; import com.micromap.model.Authorities; import com.micromap.util.HibernateUtil; import java.io.Serializable; import java.util.List; import org.hibernate.Criteria; import org.hibernate.criterion.CriteriaSpecification; import org.hibernate.criterion.Restrictions; /** * * @author cfsbs_000 */ public class AuthoritiesDAO extends GenericDAO implements Serializable { public List<Authorities> listaAuthorities() throws Exception { List<Authorities> lista = null; try { session = HibernateUtil.getSessionFactory().openSession(); Criteria criteria = session.createCriteria(Authorities.class); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); lista = criteria.list(); } catch (Exception e) { throw new Exception(e.getMessage()); } finally { session.close(); } return lista; } public Authorities buscaAuthorities(String authority) throws Exception { Authorities retorno = null; try { session = HibernateUtil.getSessionFactory().openSession(); Criteria criteria = session.createCriteria(Authorities.class); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); criteria.add(Restrictions.like("authority", authority)); retorno = (Authorities) criteria.uniqueResult(); } catch (Exception e) { throw new Exception(e.getMessage()); } finally { session.close(); } return retorno; } }