Hibernate ORM SQLQuery - 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 SQLQuery class.

This code example shows how to use the following methods:addEntity, list
 
			session.beginTransaction();
 
			SQLQuery q = session.createSQLQuery(_GET_FOOD_ITEMS);
 
			q.addEntity("FoodItem", FoodItem.class);
 
			List list = q.list();
 
			session.getTransaction().commit();
 
			return list;
		} 
		catch (Exception e) {
			throw new Exception(e);
		} 
		finally { 
			HibernateUtil.closeSession(session);
		} 
	} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:executeUpdate
        Dialect dialect = mock(Dialect.class);
        when(session.getSessionFactory()).thenReturn(sessionFactory);
        when(sessionFactory.getDialect()).thenReturn(dialect);
        when(dialect.getNativeIdentifierGeneratorClass()).thenReturn(SequenceGenerator.class);
        SQLQuery sqlQuery = mock(SQLQuery.class);
        when(session.createSQLQuery("create sequence schema.hibernate_sequence")).thenReturn(sqlQuery);
        when(sqlQuery.executeUpdate()).thenReturn(0);
 
        this.store.createHibernateSequenceIfRequired(new String[] {}, "schema", session);
 
        verify(session).createSQLQuery("create sequence schema.hibernate_sequence");
        verify(sqlQuery).executeUpdate();
    } 
 
    /** 
     * We verify that the sequence is not created if it's already in the update script. 
     */ 
    @Test
    public void createHibernateSequenceIfRequiredWhenInUpdateCommands() throws Exception
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setFirstResult
    { 
        if (firstResultIndex < maxResultIndex)
        { 
            // TODO:namedquery, JPQL, HQL => iterate, native => then don't 
 
            result = sqlQuery.setFirstResult(firstResultIndex++).setMaxResults(1).list();
        } 
 
        return result != null && !result.isEmpty() && fetchSize != 0;
    } 
 
    @Override 
    public E next() 
    { 
        if (result == null || result.isEmpty() || fetchSize == 0)
        { 
            throw new NoSuchElementException("Nothing to scroll further for: " + m.getEntityClazz());
        } 
 
        fetchSize--;
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:executeUpdate
		} 
	} 
 
	private void runStatement(String sql) throws SQLException {
		SQLQuery query = session.createSQLQuery(sql);
		query.executeUpdate();
	} 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Hibernate ORM SQLQuery Methods: