List of usage examples for org.hibernate SQLQuery addJoin
SQLQuery<T> addJoin(String tableAlias, String path);
From source file:net.chrisrichardson.foodToGo.domain.hibernate.HibernateOrderRepositoryImpl.java
License:Apache License
private SQLQuery makeSqlQuery(Session session) { SQLQuery query = session.createSQLQuery("SELECT {o.*},{r.*} " + " FROM FTGO_PLACED_ORDER o, FTGO_RESTAURANT r " + " WHERE r.restaurant_id = o.restaurant_id " + "AND o.delivery_city = :name " + " ORDER BY DELIVERY_TIME desc"); query.addEntity("o", Order.class); query.addJoin("r", "o.restaurant"); query.setParameter("name", "Oakland"); return query; }
From source file:org.anyframe.hibernate.impl.DynamicHibernateServiceImpl.java
License:Apache License
private void addJoin(SQLQuery query, Map<String, String> returnJoinMap) { if (!returnJoinMap.isEmpty()) { Set<String> keySet = returnJoinMap.keySet(); Iterator<String> keyItr = keySet.iterator(); while (keyItr.hasNext()) { String alias = keyItr.next(); String property = returnJoinMap.get(alias); query.addJoin(alias, property); }/*from w w w . j a v a 2s . c om*/ } }
From source file:org.codehaus.grepo.query.hibernate.generator.QueryGeneratorBase.java
License:Apache License
protected void applyAddJoinSetting(String alias, String path, SQLQuery query) { query.addJoin(alias, path); }
From source file:org.generationcp.middleware.manager.GermplasmDataManagerImpl.java
License:Open Source License
/** * (non-Javadoc)//from w w w. j a v a2 s .com * * @see org.generationcp.middleware.manager.api.GermplasmDataManager#getGermplasmWithAllNamesAndAncestry(java.util.Set, int) */ @SuppressWarnings("unchecked") @Override public List<Germplasm> getGermplasmWithAllNamesAndAncestry(final Set<Integer> gids, final int numberOfLevelsToTraverse) { final Monitor monitor = MonitorFactory.start("org.generationcp.middleware.manager.GermplasmDataManagerImpl" + ".getGermplasmWithAllNamesAndAncestry(Set<Integer> - SetSize(" + gids.size() + ") , int)"); try { final StringBuilder commaSeparatedListOfGids = this.getGidsAsCommaSeparatedList(gids); final SQLQuery storedProcedure = this.getActiveSession() .createSQLQuery("CALL getGermplasmWithNamesAndAncestry(:gids, :numberOfLevelsToTraverse) "); storedProcedure.setParameter("gids", commaSeparatedListOfGids.toString()); storedProcedure.setParameter("numberOfLevelsToTraverse", numberOfLevelsToTraverse); storedProcedure.addEntity("g", Germplasm.class); storedProcedure.addJoin("n", "g.names"); // Be very careful changing anything here. // The entity has been added again because the distinct root entity works on the // Last added entity storedProcedure.addEntity("g", Germplasm.class); storedProcedure.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return storedProcedure.list(); } finally { monitor.stop(); } }
From source file:org.jessma.dao.hbn.HibernateFacade.java
License:Apache License
/** * //from w w w . j a v a2s . c o m * ?SQL?EntitiesJoins * * @param firstResult : * @param maxResults : * @param sql : SQL ? * @param entities : ?? * @param joins : ?? * @param params : ? * @return : * */ protected <T> List<T> sqlQuery4(int firstResult, int maxResults, String sql, KV<String, Object>[] entities, KV<String, String>[] joins, Object... params) { SQLQuery sqlQuery = getSession().createSQLQuery(sql); for (int i = 0; i < params.length; i++) sqlQuery.setParameter(i, params[i]); if (entities != null) { for (int i = 0; i < entities.length; i++) { KV<String, Object> entity = entities[i]; String key = entity.getKey(); Object value = entity.getValue(); Class<?> v1 = (value instanceof Class) ? (Class<?>) value : null; String v2 = v1 == null ? (String) value : null; if (key == null || key.length() == 0) { if (v1 != null) sqlQuery.addEntity(v1); else sqlQuery.addEntity(v2); } else { if (v1 != null) sqlQuery.addEntity(key, v1); else sqlQuery.addEntity(key, v2); } } } if (joins != null) { for (KV<String, String> join : joins) sqlQuery.addJoin(join.getKey(), (String) join.getValue()); } if (firstResult > 0) sqlQuery.setFirstResult(firstResult); if (maxResults > 0) sqlQuery.setMaxResults(maxResults); return sqlQuery.list(); }