本文整理了Java中org.hibernate.query.NativeQuery.setFirstResult()
方法的一些代码示例,展示了NativeQuery.setFirstResult()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NativeQuery.setFirstResult()
方法的具体详情如下:
包路径:org.hibernate.query.NativeQuery
类名称:NativeQuery
方法名:setFirstResult
暂无
代码示例来源:origin: hibernate/hibernate-orm
@Test
@TestForIssue(jiraKey = "HHH-7369")
public void testPaginationWithScalarQuery() throws Exception {
doInHibernate( this::sessionFactory, session -> {
for ( int i = 0; i < 10; i++ ) {
session.persist( new Product2( i, "Kit" + i ) );
}
session.flush();
session.clear();
List list = session.createNativeQuery( "select id from Product2 where description like 'Kit%' order by id" ).list();
assertEquals(Integer.class, list.get(0).getClass()); // scalar result is an Integer
list = session.createNativeQuery( "select id from Product2 where description like 'Kit%' order by id" ).setFirstResult( 2 ).setMaxResults( 2 ).list();
assertEquals(Integer.class, list.get(0).getClass()); // this fails without patch, as result suddenly has become an array
// same once again with alias
list = session.createNativeQuery( "select id as myint from Product2 where description like 'Kit%' order by id asc" ).setFirstResult( 2 ).setMaxResults( 2 ).list();
assertEquals(Integer.class, list.get(0).getClass());
} );
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
@TestForIssue(jiraKey = "HHH-8916")
public void testPaginationWithCTEQueryWithOffset() {
// This used to throw a StringIndexOutOfBoundsException
doInHibernate( this::sessionFactory, session -> {
for ( int i = 0; i < 20; ++i ) {
session.persist( new Product2( i, "Product" + i ) );
}
session.flush();
session.clear();
List results = session
.createNativeQuery( "WITH a AS (SELECT id, description FROM Product2) SELECT id, description FROM a" )
.setFirstResult( 5 )
.setMaxResults( 10 )
.getResultList();
assertEquals( 10, results.size() );
final Object[] row = (Object[]) results.get( 0 );
assertEquals( 2, row.length );
assertEquals( Integer.class, row[ 0 ].getClass() );
assertEquals( String.class, row[ 1 ].getClass() );
} );
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
@TestForIssue(jiraKey = "HHH-7368")
public void testPaginationWithTrailingSemicolon() throws Exception {
doInHibernate( this::sessionFactory, session -> {
session.createNativeQuery( "select id from Product2 where description like 'Kit%' order by id;" )
.setFirstResult( 2 ).setMaxResults( 2 ).list();
} );
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
@TestForIssue(jiraKey = "HHH-8916")
public void testPaginationWithCTEQueryWithOffsetAndOrderBy() {
// This used to throw a StringIndexOutOfBoundsException
doInHibernate( this::sessionFactory, session -> {
for ( int i = 0; i < 20; ++i ) {
session.persist( new Product2( i, "Product" + i ) );
}
session.flush();
session.clear();
List results = session
.createNativeQuery( "WITH a AS (SELECT id, description FROM Product2) SELECT id, description FROM a ORDER BY id DESC" )
.setFirstResult( 5 )
.setMaxResults( 10 )
.getResultList();
assertEquals( 10, results.size() );
final Object[] row = (Object[]) results.get( 0 );
assertEquals( 2, row.length );
assertEquals( Integer.class, row[ 0 ].getClass() );
assertEquals( String.class, row[ 1 ].getClass() );
assertEquals( 14, row[0] );
assertEquals( "Product14", row[1] );
} );
}
代码示例来源:origin: dkpro/dkpro-jwpl
private boolean fillBuffer() {
Session session = this.wiki.__getHibernateSession();
session.beginTransaction();
List returnList = session.createNativeQuery(
"select p.name from PageMapLine as p")
.setFirstResult(dataOffset)
.setMaxResults(maxBufferSize)
.setFetchSize(maxBufferSize)
.list();
session.getTransaction().commit();
// clear the old buffer and all variables regarding the state of the buffer
titleStringBuffer.clear();
bufferOffset = 0;
bufferFillSize = 0;
titleStringBuffer.addAll(returnList);
if (titleStringBuffer.size() > 0) {
bufferFillSize = titleStringBuffer.size();
return true;
}
else {
return false;
}
}
代码示例来源:origin: com.centit.framework/centit-persistence-hibernate
public final static <T> List<T> findObjectsBySql(BaseDaoImpl<?, ?> baseDao, String ssql,
Object[] values, PageDesc pageDesc, Class<T> objectType) {
int startPos = 0;
int maxSize = 0;
if(pageDesc!=null){
startPos = pageDesc.getRowStart();
maxSize = pageDesc.getPageSize();
}
NativeQuery q = baseDao.getCurrentSession().createNativeQuery(ssql);
setQueryParameter(q,values);
if (maxSize > 0)
q.setMaxResults(maxSize);
if (startPos >= 0)
q.setFirstResult(startPos);
if(objectType!=null)
q.addEntity(objectType);
List<T> l = q.list();
if(l!=null && pageDesc!=null){
if(maxSize>0){
q = baseDao.getCurrentSession().createNativeQuery(QueryUtils.buildGetCountSQL(ssql));
setQueryParameter(q,values);
pageDesc.setTotalRows(Integer.valueOf(q.list().get(0).toString()));
}else
pageDesc.setTotalRows(l.size());
}
return l;
}
代码示例来源:origin: com.centit.framework/centit-persistence-hibernate
q.setMaxResults(maxSize);
if (startPos >= 0)
q.setFirstResult(startPos);
代码示例来源:origin: vladmihalcea/high-performance-java-persistence
"JOIN post p ON c.post_id = p.id " +
"ORDER BY p.id")
.setFirstResult(pageStart)
.setMaxResults(pageSize)
.setResultTransformer(new AliasToBeanResultTransformer(PostCommentSummary.class))
内容来源于网络,如有侵权,请联系作者删除!