Hibernate ORM Query - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Hibernate ORM Query class.

This code example shows how to use the following methods: list, setFirstResult, setMaxResults
	 
	public List<T> queryEntities(String hql, int offset, int limit, Object[] params) {
		Session session = PersistContext.getSession(isCloudStackSession);
		Query query = session.createQuery(hql);
		QueryHelper.bindParameters(query, params);
		query.setFirstResult(offset);
		query.setMaxResults(limit);
		return (List<T>)query.list();
	} 
	 
	public int executeUpdate(String hql, Object[] params) {
		Session session = PersistContext.getSession(isCloudStackSession);
		Query query = session.createQuery(hql);
		QueryHelper.bindParameters(query, params);
 
		return query.executeUpdate();
	} 
} 
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: setFetchSize
		itemReader.setSessionFactory(sessionFactory);
		itemReader.setQueryString("testQuery");
		itemReader.setUseStatelessSession(false);
 
		when(sessionFactory.openSession()).thenReturn(session);
		when(session.createQuery("testQuery")).thenReturn(scrollableResults);
		when(scrollableResults.setFetchSize(0)).thenReturn(scrollableResults);
		when(session.close()).thenReturn(null);
 
		itemReader.open(new ExecutionContext());
		itemReader.close();
	} 
 
} 
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: list
 
        // STUB 
 
        List<?> listResult = Collections.emptyList();
 
        when(session.createQuery(anyString())).thenReturn(query);
        when(query.list()).thenReturn(listResult);
 
        // EXECUTE 
 
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("key1", "value1"); 
        params.put("key2", "value2"); 
 
        Object result = adapter.lookupByQuery("query", params);
 
        // VERIFY 
 
        assertSame(listResult, result);
 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: setTimeout
	 * @param sessionFactory Hibernate SessionFactory that the Query was created for 
	 * (may be {@code null}) 
	 * @see org.hibernate.Query#setTimeout 
	 */ 
	public static void applyTransactionTimeout(Query query, SessionFactory sessionFactory) { 
		Assert.notNull(query, "No Query object specified"); 
		if (sessionFactory != null) { 
			SessionHolder sessionHolder = 
					(SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory); 
			if (sessionHolder != null && sessionHolder.hasTimeout()) { 
				query.setTimeout(sessionHolder.getTimeToLiveInSeconds()); 
			} 
		} 
	} 
 
	/** 
	 * Apply the current transaction timeout, if any, to the given 
	 * Hibernate Criteria object. 
	 * @param criteria the Hibernate Criteria object 
	 * @param sessionFactory Hibernate SessionFactory that the Criteria was created for 
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: list
        when(doc.getFullName()).thenReturn(fullName);
 
        Query query = mock(Query.class);
        String statement = "select doc.fullName from XWikiDocument as doc where doc.fullName=:fullName"
            + " and doc.language=:language"; 
        when(session.createQuery(statement)).thenReturn(query);
        when(query.list()).thenReturn(Collections.singletonList(fullName));
 
        assertTrue(store.exists(doc, context));
 
        verify(query).setString("fullName", fullName);
        verify(query).setString("language", Locale.ENGLISH.toString());
    } 
} 
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: list
		expectedFoos.add(new Foo(3, "bar3", 3));
		expectedFoos.add(new Foo(4, "bar4", 4));
		expectedFoos.add(new Foo(5, "bar5", 5));
 
		@SuppressWarnings("unchecked") 
		List<Foo> actualFoos = query.list();
 
		assertEquals(actualFoos, expectedFoos);
 
	} 
 
} 
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: list, setFirstResult, setMaxResults, setParameter
	} 
 
	@Test
	public void testExecuteFinder_ResultList() throws Exception {
		List<EmailTemplate> expectedTemplates = Arrays.asList(newEmailTemplate());
		expect(session.createQuery("Select e from EmailTemplate e where id = ?")).andReturn(query);
		expect(query.setParameter(0, "fakeValue")).andReturn(query);
		expect(query.setFirstResult(0)).andReturn(query);
		expect(query.setMaxResults(10)).andReturn(query);
		expect(query.list()).andReturn(expectedTemplates);
		replay(sessionFactory, session, query);
		Method method = this.getClass().getMethod("methodList");
		List<?> templates = (List<?>) impl.executeFinder("Select e from $TYPE e where id = ?",
				new Object[] { "fakeValue" }, method, 0, 10);
		verify(session, sessionFactory, query);
		assertEquals(expectedTemplates.get(0), templates.get(0));
	} 
 
	@Test
	public void testExecuteUpdate() { 
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: list
                + "JOIN c.dayAssignments d where c.scenario = :scenario" 
                + addQueryConditionForInitAndEndDate(initInclusive,
                        endInclusive) + addQueryConditionsForResource(resource);
        Query query = getSession().createQuery(queryString);
        query = query.setParameter("scenario", scenario);
        addInitAndEndParameters(query, initInclusive, endInclusive);
        addResourceParameter(query, resource);
        return query.list();
    } 
 
    private String addQueryConditionForInitAndEndDate(LocalDate initInclusive,
            LocalDate endInclusive) {
        String initCondition = initInclusive != null ? " and d.day >= :init"
                : ""; 
        String endCondition = endInclusive != null ? " and d.day <= :end" : "";
        return initCondition + endCondition;
    } 
 
    private String addQueryConditionsForResource(Resource resource) {
        return resource != null ? " and d.resource = :resource " : "";
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: setFirstResult, setMaxResults
			} 
		}); 
	} 
	 
	protected static void setPage(Query qu,int pageIndex,int pageSize){
		qu.setMaxResults(pageSize);
		qu.setFirstResult((pageIndex - 1) * pageSize);
		 
	} 
} 
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: list, setParameter
 
				String queryString = "from PageEditareaT  as pea where pea.pageid=:pageid and pea.typeid=:typeid and pea.state=:state";
 
				public Object doInHibernate(Session session) throws HibernateException, SQLException {
					Query query = session.createQuery(queryString);
					query.setParameter("pageid", pageid);
					query.setParameter("typeid", typeid);
					query.setParameter("state", state);
					List list = query.list();
					return list;
				} 
			}); 
			if (list.size() > 0) {
				return list;
			} 
			return null; 
		} catch (RuntimeException re) {
			log.error("find all PageEditareaT error state", re);
			throw re;
		} 
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Hibernate ORM Query Methods: