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: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.TaskDefinitionDaoImpl.java
@Override public List<TaskDefinition> getAllByFullTextService(String parameter, int minResult, int maxResult, Order orde) {/*w w w .j a v a 2 s .c o m*/ FullTextSession fullTextSession = Search.getFullTextSession(getCurrentSession()); Criteria criteria = fullTextSession.createCriteria(TaskDefinition.class).setFetchMode("modemDefinition", FetchMode.JOIN); org.apache.lucene.search.Sort sort; if (orde.isAscending()) { sort = new Sort(new SortField(orde.getPropertyName(), SortField.STRING_VAL)); } else { sort = new Sort(new SortField(orde.getPropertyName(), SortField.STRING_VAL, true)); } System.out.println("Nilai sorrt " + orde.getPropertyName()); FullTextQuery fullTextQuery1 = doSearchFullText(parameter, fullTextSession); fullTextQuery1.setCriteriaQuery(criteria); fullTextQuery1.setFirstResult(minResult); fullTextQuery1.setMaxResults(maxResult); fullTextQuery1.setSort(sort); return fullTextQuery1.list(); }
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.kanjiportal.portal.admin.LuceneManagementAction.java
License:Open Source License
public void reIndexKanji() { FullTextSession fullTextSession = (FullTextSession) entityManager.getDelegate(); fullTextSession.setFlushMode(FlushMode.MANUAL); fullTextSession.setCacheMode(CacheMode.IGNORE); log.debug("Indexing kanjis ...."); long beforeKanjis = System.currentTimeMillis(); //Scrollable results will avoid loading too many objects in memory ScrollableResults results = fullTextSession.createCriteria(Kanji.class).setFetchSize(BATCH_SIZE) .setFetchMode("meanings", FetchMode.JOIN).setFetchMode("meanings.meaning.language", FetchMode.JOIN) .scroll(ScrollMode.FORWARD_ONLY); int index = 0; while (results.next()) { index++;/*from w w w . j ava 2 s.com*/ fullTextSession.index(results.get(0)); //index each element if (index % BATCH_SIZE == 0) { entityManager.flush(); entityManager.clear(); log.debug("flush()"); } } log.debug("Indexing kanjis done"); long afterKanjis = System.currentTimeMillis(); facesMessages.add("Kanji Indexing done in #0 ms", afterKanjis - beforeKanjis); }
From source file:com.kanjiportal.portal.admin.LuceneManagementAction.java
License:Open Source License
public void reIndexDictionary() { FullTextSession fullTextSession = (FullTextSession) entityManager.getDelegate(); fullTextSession.setFlushMode(FlushMode.MANUAL); fullTextSession.setCacheMode(CacheMode.IGNORE); long beforeDictionary = System.currentTimeMillis(); //Scrollable results will avoid loading too many objects in memory ScrollableResults results = fullTextSession.createCriteria(Dictionary.class).setFetchSize(BATCH_SIZE) .setFetchMode("translations", FetchMode.JOIN).setFetchMode("translations.language", FetchMode.JOIN) .scroll(ScrollMode.FORWARD_ONLY); int index = 0; while (results.next()) { index++;/*w w w . j a v a 2s . c om*/ fullTextSession.index(results.get(0)); //index each element if (index % BATCH_SIZE == 0) { entityManager.flush(); entityManager.clear(); log.debug("flush()"); } } log.debug("Indexing dictionary done"); long afterDictionary = System.currentTimeMillis(); facesMessages.add("Dictionary Indexing done in #0 ms", afterDictionary - beforeDictionary); }
From source file:com.luxsoft.siipap.dao.core.ClienteDaoImpl.java
License:Apache License
public List<Cliente> buscarClientePorClave(final String clave) { return getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { EventList<Cliente> res = GlazedLists.eventList(session.createCriteria(Cliente.class) .setFetchMode("contactos", FetchMode.JOIN).setFetchMode("telefonos", FetchMode.JOIN) .add(Restrictions.like("clave", clave, MatchMode.START).ignoreCase()).setMaxResults(500) .list());//from w ww. j ava 2s. c om return new UniqueList<Cliente>(res, GlazedLists.beanPropertyComparator(Cliente.class, "id")); } }); }
From source file:com.luxsoft.siipap.dao.core.ClienteDaoImpl.java
License:Apache License
public List<Cliente> buscarClientePorNombre(final String nombre) { return getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { EventList<Cliente> res = GlazedLists.eventList(session.createCriteria(Cliente.class) .setFetchMode("contactos", FetchMode.JOIN).setFetchMode("telefonos", FetchMode.JOIN) .add(Restrictions.like("nombre", nombre, MatchMode.ANYWHERE).ignoreCase()) .setMaxResults(500).list()); return new UniqueList<Cliente>(res, GlazedLists.beanPropertyComparator(Cliente.class, "id")); }//from ww w .j ava 2 s .c om }); }
From source file:com.mycompany.CRMFly.hibernateAccess.EmployeesDAOImpl.java
@Override public List<Contracts> getContractsOnWorker(Long id) { org.hibernate.Session sess = sessionFactory.getCurrentSession(); // sess.enableFetchProfile("employees-with-contracts"); // Employees employee = (Employees) sess. // get(Employees.class, id); // return employee.getResponsibleForContracts(); return sessionFactory.getCurrentSession().createCriteria(Contracts.class) .setFetchMode("ResponsibleManager", FetchMode.JOIN).add(Restrictions.eq("id", id)).list(); }
From source file:com.mycompany.CRMFly.hibernateAccess.EmployeesDAOImpl.java
@Override public List<Projects> getProjectsEmployeeResponsibleFor(Long id) { org.hibernate.Session sess = sessionFactory.getCurrentSession(); // sess.enableFetchProfile("managers-with-projects"); // Employees employee = (Employees) sess. // get(Employees.class, id); // return employee.getResponsibleForProjects(); return sessionFactory.getCurrentSession().createCriteria(Projects.class) .setFetchMode("ResponsibleManager", FetchMode.JOIN).add(Restrictions.eq("id", id)).list(); }
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 .j a va2 s . c o 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; }