package com; // Generated 3 juin 2012 15:13:40 by Hibernate Tools 3.4.0.CR1 import java.util.List; import javax.faces.model.SelectItem; import javax.naming.InitialContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.LockMode; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistryBuilder; import static org.hibernate.criterion.Example.create; import com.Rubrique; /** * Home object for domain model class Rubrique. * @see com.Rubrique * @author Hibernate Tools */ public class RubriqueHome { private static final Log log = LogFactory.getLog(RubriqueHome.class); private final SessionFactory sessionFactory = getSessionFactory(); private Session session = null; protected SessionFactory getSessionFactory() { try { Configuration cfg = new Configuration(); cfg.configure(); ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry(); SessionFactory factory = cfg.buildSessionFactory(serviceRegistry); return factory; } catch (Exception e) { log.error("Could not locate SessionFactory in JNDI", e); throw new IllegalStateException("Could not locate SessionFactory in JNDI"); } } public void persist(Rubrique transientInstance) { log.debug("persisting Rubrique instance"); try { sessionFactory.getCurrentSession().persist(transientInstance); log.debug("persist successful"); } catch (RuntimeException re) { log.error("persist failed", re); throw re; } } public void attachDirty(Rubrique instance) { log.debug("attaching dirty Rubrique instance"); try { sessionFactory.getCurrentSession().saveOrUpdate(instance); log.debug("attach successful"); } catch (RuntimeException re) { log.error("attach failed", re); throw re; } } public void attachClean(Rubrique instance) { log.debug("attaching clean Rubrique instance"); try { sessionFactory.getCurrentSession().lock(instance, LockMode.NONE); log.debug("attach successful"); } catch (RuntimeException re) { log.error("attach failed", re); throw re; } } public void delete(Rubrique persistentInstance) { log.debug("deleting Rubrique instance"); try { sessionFactory.getCurrentSession().delete(persistentInstance); log.debug("delete successful"); } catch (RuntimeException re) { log.error("delete failed", re); throw re; } } public Rubrique merge(Rubrique detachedInstance) { log.debug("merging Rubrique instance"); try { Rubrique result = (Rubrique) sessionFactory.getCurrentSession() .merge(detachedInstance); log.debug("merge successful"); return result; } catch (RuntimeException re) { log.error("merge failed", re); throw re; } } public Rubrique findById( java.lang.String id) { log.debug("getting Rubrique instance with id: " + id); try { Rubrique instance = (Rubrique) sessionFactory.getCurrentSession() .get("com.Rubrique", id); if (instance==null) { log.debug("get successful, no instance found"); } else { log.debug("get successful, instance found"); } return instance; } catch (RuntimeException re) { log.error("get failed", re); throw re; } } public List findByExample(Rubrique instance) { log.debug("finding Rubrique instance by example"); try { List results = (List) sessionFactory.getCurrentSession() .createCriteria("com.Rubrique") .add( create(instance) ) .list(); log.debug("find by example successful, result size: " + results.size()); return results; } catch (RuntimeException re) { log.error("find by example failed", re); throw re; } } public List selection(){ List listerubrique=null; try{ session =sessionFactory.openSession(); Query query = session.createQuery("from Rubrique"); listerubrique=query.list(); }catch (RuntimeException re) { log.error("find by example failed", re); throw re; } return listerubrique; } }