List of usage examples for org.hibernate.criterion Restrictions allEq
@SuppressWarnings("UnusedDeclaration") public static Criterion allEq(Map<String, ?> propertyNameValues)
From source file:br.com.loja.framework.hibernate.dao.AbstractDAOHibernate.java
@Override public List<T> list(Map<String, ?> properties, boolean cacheable) { List<T> entities = null; if (getSession() != null) { entities = new ArrayList<>(); if (properties != null) { if (!properties.isEmpty()) { try { begin();//from www. j a v a2 s . com entities = getSession().createCriteria(clazz).setCacheable(cacheable) .add(Restrictions.allEq(properties)).list(); commit(); } catch (HibernateException e) { //TODO implemetar log System.err.println(e.getMessage()); rollback(); e.printStackTrace(); } finally { close(); } } } } return entities; }
From source file:cn.newtouch.hibernate.dao.StudentDAO.java
License:Open Source License
public static void main(String[] args) { try {//ww w .j av a 2 s. c o m Session session = HibernateUtil.getSession(); String hql = " from Student"; List<Student> userList = session.createQuery(hql).list(); System.out.println("=====1=======" + userList.size()); Criteria criteria = session.createCriteria(Student.class); // criteria.add(Restrictions.eq("name", "HZZ")); // map criteria.add(Restrictions.allEq(new HashMap<String, String>())); // criteria.add(Restrictions.gt("id", new Long(1))); // criteria.add(Restrictions.ge("id", new Long(1))); // ? criteria.add(Restrictions.lt("id", new Long(1))); // ? criteria.add(Restrictions.le("id", new Long(1))); // xxxyyy criteria.add(Restrictions.between("id", new Long(1), new Long(2))); // ? criteria.add(Restrictions.like("name", "H")); // and? criteria.add(Restrictions.and(Restrictions.ge("id", new Long(1)), Restrictions.ge("id", new Long(1)))); // or? criteria.add(Restrictions.or(Restrictions.ge("id", new Long(1)), Restrictions.ge("id", new Long(1)))); userList = criteria.list(); System.out.println("=====2=======" + userList.size()); Student student = new Student(); student.setId(123456L); student.setName("hzz"); student.setAge(14); save(student); System.out.println("OK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.ipn.escom.ageinnn.usuario.service.AspiranteServceImpl.java
private List<Aspirante> findAllAspirantesWithFolio(Curso curso, PeriodoAdmision periodoAdmision) { List<Aspirante> aspirantes = new ArrayList<>(); try {/*from w w w. j a va 2s.c o m*/ Map<String, Object> properties = new HashMap<String, Object>(); properties.put("cursoId", curso.getId()); properties.put("periodoAdmisionId", periodoAdmision.getId()); session = Service.getSessionFactory().getCurrentSession(); session.beginTransaction(); aspirantes = session.createCriteria(Aspirante.class).add(Restrictions.allEq(properties)).list(); session.getTransaction().commit(); } catch (Exception e) { session.getTransaction().rollback(); } return aspirantes; }
From source file:com.jredrain.dao.HibernateDao.java
License:Apache License
public <T> List<T> getByProperties(Class<T> entityClass, Map<String, Object> properties) { entityClass = getEntityClass(entityClass); return createCriteria(entityClass).add(Restrictions.allEq(properties)).list(); }
From source file:com.jscompany.ebsystem.entitymanager.TransactionManager.java
@Override public <T> T findObjectByParameter(Class entity, Map<String, Object> paramt) { T ob = null;/*from w w w .ja v a 2s . c o m*/ try { sess = HiberUtil.getSession(); cq = sess.createCriteria(entity); cq.add(Restrictions.allEq(paramt)); ob = (T) cq.uniqueResult(); Hibernate.initialize(ob); } catch (HibernateException e) { Logger.getLogger(TransactionManager.class.getName()).log(Level.SEVERE, null, e); } return ob; }
From source file:com.jscompany.ebsystem.entitymanager.TransactionManager.java
@Override public <T> List<T> findObjectByParameterList(Class entity, Map<String, Object> paramt) { List<T> ob = null;/*from w ww . ja v a 2 s. c om*/ try { sess = HiberUtil.getSession(); cq = sess.createCriteria(entity); cq.add(Restrictions.allEq(paramt)); ob = (List<T>) cq.list(); ob.size(); Hibernate.initialize(ob); } catch (HibernateException e) { Logger.getLogger(TransactionManager.class.getName()).log(Level.SEVERE, null, e); } return ob; }
From source file:com.qcadoo.model.api.search.SearchRestrictions.java
License:Open Source License
/** * Creates criterion which checks if all given fields match given values. * // w ww . j a v a 2 s. co m * @param values * map where key is a field's name and value is the expected value * @return criterion */ public static SearchCriterion allEq(final Map<String, Object> values) { return new SearchCriterionImpl(Restrictions.allEq(values)); }
From source file:com.vmware.bdd.dal.impl.DatastoreDAO.java
License:Open Source License
@Override public List<VcDatastoreEntity> findByNameAndType(DatastoreType type, String name) { logger.debug("findByNameAndType, name: " + name + "type: " + type); Map<String, Object> propertyNameValues = new HashMap<String, Object>(); propertyNameValues.put("name", name); propertyNameValues.put("type", type); return this.findByCriteria(Restrictions.allEq(propertyNameValues)); }
From source file:com.vmware.bdd.dal.impl.NodeGroupDAO.java
License:Open Source License
@Override public NodeGroupEntity findByName(ClusterEntity cluster, String groupName) { Map<String, Object> conditions = new HashMap<String, Object>(); conditions.put("cluster", cluster); conditions.put("name", groupName); return findUniqueByCriteria(Restrictions.allEq(conditions)); }
From source file:com.vmware.bdd.dal.impl.ResourcePoolDAO.java
License:Open Source License
@Override @Transactional(readOnly = true)/*w ww . j a va 2s.co m*/ public VcResourcePoolEntity findByClusterAndRp(String vcCluster, String vcRp) { logger.debug("findByClusterAndRp. cluster:" + vcCluster); Map<String, String> propertyNameValues = new HashMap<String, String>(); propertyNameValues.put("vcCluster", vcCluster); propertyNameValues.put("vcResourcePool", vcRp); VcResourcePoolEntity entity = findUniqueByCriteria(Restrictions.allEq(propertyNameValues)); return entity; }