List of usage examples for org.hibernate Criteria setFetchMode
public Criteria setFetchMode(String associationPath, FetchMode mode) throws HibernateException;
From source file:com.inkubator.hrm.dao.impl.WtHolidayDaoImpl.java
@Override public List<WtHoliday> getListPublicNonReligionHolidayBetweenDate(Date start, Date end) { Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); criteria.setFetchMode("religion", FetchMode.JOIN); criteria.add(Restrictions.ge("holidayDate", start)); criteria.add(Restrictions.le("holidayDate", end)); criteria.add(Restrictions.isNull("religion")); return criteria.list(); }
From source file:com.inkubator.hrm.dao.impl.WtOverTimeDaoImpl.java
@Override public WtOverTime getEntityByPkFetchApprovalDefinition(Long id) { Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); criteria.setFetchMode("approvalDefinitionOTs", FetchMode.JOIN); criteria.setFetchMode("approvalDefinitionOTs.approvalDefinition", FetchMode.JOIN); criteria.add(Restrictions.eq("id", id)); return (WtOverTime) criteria.uniqueResult(); }
From source file:com.inkubator.hrm.dao.impl.WtOverTimeDaoImpl.java
@Override public WtOverTime getEntityByPkWithDetail(Long id) { Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); criteria.add(Restrictions.eq("id", id)); criteria.setFetchMode("wtHitungLembur", FetchMode.JOIN); return (WtOverTime) criteria.uniqueResult(); }
From source file:com.inkubator.sms.gateway.dao.impl.UserRoleDaoImpl.java
@Override public List<UserRole> getByUserId(Long id) { Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); criteria.createAlias("user", "user"); criteria.add(Restrictions.eq("user.id", id)); criteria.addOrder(Order.desc("role")); criteria.setFetchMode("role", FetchMode.JOIN); return criteria.list(); }
From source file:com.kunckle.jetpower.core.base.search.SearchAdapter.java
License:Apache License
/** * Criteria//from w w w .j a v a2 s . c o m * * @param criteria Session?Criteria * @return ?Criteria? */ public Criteria getCriteria(Criteria criteria) { if (criterions != null) { for (Criterion criterion : criterions) { criteria.add(criterion); } } if (projectionList != null) { criteria.setProjection(projectionList); } if (aliaes != null) { for (String key : aliaes.keySet()) { criteria.createAlias(key, aliaes.get(key)); } } if (fetchModes != null) { for (String key : fetchModes.keySet()) { criteria.setFetchMode(key, fetchModes.get(key)); } } return criteria; }
From source file:com.painiu.core.dao.hibernate.PhotoDAOHibernate.java
License:Open Source License
static Criteria buildPhotoCriteria(final Session session, User user, String[] tags, boolean taggedAll, String text, Relation relation, boolean count) { Criteria criteria = session.createCriteria(Photo.class); if (user != null) { criteria.add(Restrictions.eq("user", user)); if (relation != null) { criteria.add(/*from w w w . ja va 2 s. co m*/ Restrictions.sqlRestriction(" {alias}.privacy & ? > 0", relation, UserTypes.relation())); } } else { criteria.add( Restrictions.sqlRestriction(" {alias}.privacy & ? > 0", Relation.NONE, UserTypes.relation())); criteria.setFetchMode("user", FetchMode.JOIN); } //if (user == null && group == null) { if (user == null) { Disjunction disjState = Restrictions.disjunction(); disjState.add(Restrictions.eq("state", Photo.State.USER_POPULAR)); disjState.add(Restrictions.eq("state", Photo.State.USER_COMMENDATORY)); disjState.add(Restrictions.eq("state", Photo.State.USER_SENIOR)); criteria.add(disjState); } //if (album != null) { // criteria.createAlias("albumPhotos", "ap"); // criteria.add( Restrictions.eq("ap.album", album) ); //} //if (group != null) { // criteria.createAlias("groupPhotos", "gp"); // criteria.add( Restrictions.eq("gp.group", group) ); //} if ((tags != null && tags.length > 0) || text != null) { Criteria subCriteria = criteria.createCriteria("photoTags", "tags"); if (tags != null && tags.length > 0) { if (taggedAll) { Conjunction conj = Restrictions.conjunction(); for (int i = 0; i < tags.length; i++) { conj.add(Restrictions.eq("tagName", tags[i])); } subCriteria.add(conj); } else { Disjunction disj = Restrictions.disjunction(); for (int i = 0; i < tags.length; i++) { disj.add(Restrictions.eq("tagName", tags[i])); } subCriteria.add(disj); } } if (text != null) { Disjunction disj = Restrictions.disjunction(); disj.add(Restrictions.like("title", text, MatchMode.ANYWHERE)); disj.add(Restrictions.like("description", text, MatchMode.ANYWHERE)); disj.add(Restrictions.eq("tags.tagName", text)); criteria.add(disj); } } // TODO order parameters if (!count) { /*if (album != null) { criteria.addOrder(Order.asc("ap.position")); } else*/ /*if (group != null) { criteria.addOrder(Order.asc("gp.position")); } else {*/ criteria.addOrder(Order.desc("timestamp")); //} } // distinct ? if ((tags != null && tags.length > 1) || text != null) { ProjectionList proj = Projections.projectionList(); proj.add(Projections.property("id")).add(Projections.property("title")) .add(Projections.property("width")).add(Projections.property("height")) .add(Projections.property("address.host")).add(Projections.property("address.dir")) .add(Projections.property("address.filename")).add(Projections.property("address.secret")) .add(Projections.property("address.username")).add(Projections.property("address.fileKey")); if (user == null) { criteria.createAlias("user", "user"); proj.add(Projections.property("user.id")).add(Projections.property("user.username")) .add(Projections.property("user.nickname")).add(Projections.property("user.buddyIcon.host")) .add(Projections.property("user.buddyIcon.dir")) .add(Projections.property("user.buddyIcon.filename")) .add(Projections.property("user.buddyIcon.username")) .add(Projections.property("user.buddyIcon.fileKey")); } criteria.setProjection(Projections.distinct(proj)); criteria.setResultTransformer(new PhotoBeanResultTransformer()); } return criteria; }
From source file:com.perceptive.epm.perkolcentral.dataaccessor.LicensePurchaseDataAccessor.java
public ArrayList<Licensepurchase> getAllLicensePurchaseInformation() throws ExceptionWrapper { Session session = hibernateTemplate.getSessionFactory().openSession(); boolean isInTransaction = session.getTransaction() != null; Transaction tx = null;/*from ww w . ja va2 s.co m*/ if (!isInTransaction) { tx = session.beginTransaction(); } ArrayList<Licensepurchase> licensepurchases = new ArrayList<Licensepurchase>(); try { Criteria criteria = session.createCriteria(Licensepurchase.class); criteria.setFetchMode("licensemaster", FetchMode.JOIN); for (Object obj : criteria.list()) { Licensepurchase licensepurchase = (Licensepurchase) obj; licensepurchases.add(licensepurchase); } } catch (Exception ex) { throw new ExceptionWrapper(ex); } finally { { if (!isInTransaction && tx.isActive()) { tx.commit(); } session.close(); } } return licensepurchases; }
From source file:com.puertobahia.iceberg.dao.impl.UsuarioDAOImpl.java
@Override public List<Usuario> getAllUsuario() { Criteria crit = getSession().createCriteria(Usuario.class); crit.setFetchMode("zona", FetchMode.JOIN); return crit.list(); }
From source file:com.puertobahia.iceberg.dao.impl.ZonaDAOImpl.java
@Override public Zona getById(Long id) { Criteria crit = getSession().createCriteria(Zona.class); crit.add(Restrictions.idEq(id));/*from w w w . ja v a 2 s. com*/ crit.setFetchMode("usuario", FetchMode.JOIN); crit.setFetchMode("usuario.empleado", FetchMode.JOIN); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); crit.setFetchMode("consejos_comunitario", FetchMode.JOIN); crit.createAlias("consejos_comunitario", "consejo", JoinType.LEFT_OUTER_JOIN); crit.add(Restrictions.or(Restrictions.and(Restrictions.eq("consejo.estado", 0)), Restrictions.isNull("consejo.estado"))); return (Zona) crit.uniqueResult(); /*Criteria crit = getSession().createCriteria(Zona.class); crit.add(Restrictions.idEq(id)); crit.setFetchMode("usuario", FetchMode.JOIN); crit.setFetchMode("usuario.empleado", FetchMode.JOIN); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); Zona zona = (Zona) crit.uniqueResult(); Criteria crit2 = getSession().createCriteria(ConsejoComunitario.class); zona.setConsejos_comunitario(crit2.add(Restrictions.and(Restrictions.idEq(zona.getId()),Restrictions.eq("estado", 0))).list()); return zona;*/ }
From source file:com.scopix.periscope.corporatestructuremanagement.dao.CorporateStructureManagementHibernateDAOImpl.java
License:Open Source License
/** * Obtain a list of EvidenceExtractionServicesServer object using filters. * * @param eess Filter object/*from www .j ava 2 s . co m*/ * @return List<EvidenceExtractionServicesServer> List of EvidenceExtractionServicesServer objects */ @Override public List<EvidenceExtractionServicesServer> getEvidenceExtractionServicesServersList( EvidenceExtractionServicesServer eess) { List<EvidenceExtractionServicesServer> list = null; Criteria criteria = this.getSession().createCriteria(EvidenceExtractionServicesServer.class); criteria.addOrder(Order.asc("id")); if (eess != null) { if (eess.getEvidenceServicesServer() != null && eess.getEvidenceServicesServer().getId() != null && eess.getEvidenceServicesServer().getId() > 0) { criteria.add( Restrictions.eq("evidenceServicesServer.id", eess.getEvidenceServicesServer().getId())); } if (eess.getUrl() != null && eess.getUrl().length() > 0) { criteria.add(Restrictions.ilike("url", eess.getUrl(), MatchMode.ANYWHERE)); } if (eess.getStores() != null && eess.getStores().size() > 0) { List<String> names = new LinkedList<String>(); for (Store store : eess.getStores()) { names.add(store.getName()); } criteria.setFetchMode("Place", FetchMode.JOIN).add(Restrictions.in("name", names)); } } list = criteria.list(); return list; }