List of usage examples for org.hibernate FetchMode JOIN
FetchMode JOIN
To view the source code for org.hibernate FetchMode JOIN.
Click Source Link
From source file:de.appsolve.padelcampus.db.dao.generic.BaseEntityDAO.java
@Override public Page<T> findAllByFuzzySearch(String search, Set<Criterion> criterions, String... associations) { Criteria criteria = getCriteria();//from w w w. j ava 2 s .c om for (String association : associations) { criteria.setFetchMode(association, FetchMode.JOIN); } List<Criterion> predicates = new ArrayList<>(); for (String indexedPropery : getIndexedProperties()) { if (!StringUtils.isEmpty(search)) { String[] searchTerms = search.split(" "); for (String searchTerm : searchTerms) { predicates.add(Restrictions.ilike(indexedPropery, searchTerm, MatchMode.ANYWHERE)); } } } if (!predicates.isEmpty()) { criteria.add(Restrictions.or(predicates.toArray(new Criterion[predicates.size()]))); } if (criterions != null) { for (Criterion c : criterions) { criteria.add(c); } } criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); @SuppressWarnings("unchecked") List<T> objects = criteria.list(); sort(objects); PageImpl<T> page = new PageImpl<>(objects); return page; }
From source file:de.appsolve.padelcampus.db.dao.generic.BaseEntityDAO.java
@Override @SuppressWarnings("unchecked") public T findByUUIDFetchEagerly(final String uuid, String... associations) { Criteria criteria = getCriteria();//from w w w . j a v a 2 s . co m for (String association : associations) { criteria.setFetchMode(association, FetchMode.JOIN); } criteria.add(Property.forName("UUID").eq(uuid)); return (T) criteria.uniqueResult(); }
From source file:de.appsolve.padelcampus.db.dao.generic.BaseEntityDAO.java
@Override @SuppressWarnings("unchecked") public T findByIdFetchEagerly(final long id, String... associations) { Criteria criteria = getCriteria();//from ww w.j a v a 2 s .co m for (String association : associations) { criteria.setFetchMode(association, FetchMode.JOIN); } criteria.add(Property.forName("id").eq(id)); return (T) criteria.uniqueResult(); }
From source file:de.appsolve.padelcampus.db.dao.generic.BaseEntityDAO.java
@Override public List<T> findAllFetchEagerly(String... associations) { Criteria crit = getCriteria();//from w ww . ja v a 2 s.c om for (String association : associations) { crit.setFetchMode(association, FetchMode.JOIN); } //we only want unique results //see http://stackoverflow.com/questions/18753245/one-to-many-relationship-gets-duplicate-objects-whithout-using-distinct-why crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); @SuppressWarnings("unchecked") List<T> list = (List<T>) crit.list(); sort(list); return list; }
From source file:de.appsolve.padelcampus.db.dao.generic.BaseEntityDAO.java
@Override public List<T> findAllFetchEagerlyWithAttributes(Map<String, Object> attributeMap, String... associations) { Criteria crit = getCriteria();//from w w w.ja v a 2 s . c o m for (String association : associations) { crit.setFetchMode(association, FetchMode.JOIN); } for (Map.Entry<String, Object> entry : attributeMap.entrySet()) { crit.add(Restrictions.eq(entry.getKey(), entry.getValue())); } //we only want unique results //see http://stackoverflow.com/questions/18753245/one-to-many-relationship-gets-duplicate-objects-whithout-using-distinct-why crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); @SuppressWarnings("unchecked") List<T> list = (List<T>) crit.list(); sort(list); return list; }
From source file:de.decidr.model.commands.user.GetUserPropertiesCommand.java
License:Apache License
@SuppressWarnings("unchecked") @Override/*w w w. j a v a 2 s . com*/ public void transactionAllowed(TransactionStartedEvent evt) throws TransactionException { users = new ArrayList<User>(0); if ((userIds == null) || userIds.isEmpty()) { return; } Criteria crit = evt.getSession().createCriteria(User.class); for (String propertyToGet : propertiesToGet) { crit.setFetchMode(propertyToGet, FetchMode.JOIN); } crit.add(Restrictions.in("id", userIds)); users = crit.list(); }
From source file:de.decidr.model.commands.workflowmodel.GetPublishedWorkflowModelsCommand.java
License:Apache License
@SuppressWarnings("unchecked") @Override//from w w w.ja v a 2 s . c om public void transactionAllowed(TransactionStartedEvent evt) throws TransactionException { PaginatingCriteria crit = new PaginatingCriteria(WorkflowModel.class, evt.getSession()); /* * We only want published workflow models. */ new EqualsFilter(true, "published", true).apply(crit); /* * Make the "tenant" property available even after the session has been * closed. */ crit.setFetchMode("tenant", FetchMode.JOIN); Filters.apply(crit, filters, paginator); result = crit.setResultTransformer(CriteriaSpecification.ROOT_ENTITY).list(); }
From source file:de.forsthaus.backend.dao.impl.MyCalendarEventDAOImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from ww w. ja va 2 s. co m public List<MyCalendarEvent> getAllCalendarEventsByUserId(long usrId) { DetachedCriteria criteria = DetachedCriteria.forClass(MyCalendarEvent.class); criteria.add(Restrictions.eq("secUser.id", usrId)); criteria.setFetchMode("secUser", FetchMode.JOIN); return getHibernateTemplate().findByCriteria(criteria); }
From source file:de.forsthaus.backend.dao.impl.MyCalendarEventDAOImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from www . j a v a 2 s . co m public List<MyCalendarEvent> getCalendarEventsForBeginDate(Date beginDate, long usrId) { DetachedCriteria criteria = DetachedCriteria.forClass(MyCalendarEvent.class); criteria.add(Restrictions.eq("beginDate", beginDate)); criteria.add(Restrictions.eq("secUser.id", usrId)); criteria.setFetchMode("secUser", FetchMode.JOIN); return getHibernateTemplate().findByCriteria(criteria); }
From source file:de.forsthaus.backend.dao.impl.MyCalendarEventDAOImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/* ww w . j a v a 2 s. co m*/ public List<MyCalendarEvent> getCalendarEventsFromToDate(Date beginDate, Date endDate, long usrId) { DetachedCriteria criteria = DetachedCriteria.forClass(MyCalendarEvent.class); criteria.add(Restrictions.ge("beginDate", beginDate)); criteria.add(Restrictions.le("endDate", endDate)); criteria.add(Restrictions.eq("secUser.id", usrId)); criteria.setFetchMode("secUser", FetchMode.JOIN); return getHibernateTemplate().findByCriteria(criteria); }