本文整理了Java中org.hibernate.query.Query.list
方法的一些代码示例,展示了Query.list
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.list
方法的具体详情如下:
包路径:org.hibernate.query.Query
类名称:Query
方法名:list
[英]Return the query results as a List. If the query contains multiple results per row, the results are returned in an instance of Object[].
[中]以列表形式返回查询结果。如果查询每行包含多个结果,则结果将在对象[]的实例中返回。
代码示例来源:origin: dropwizard/dropwizard
/**
* Get the results of a query.
*
* @param query the query to run
* @return the list of matched query results
* @see Query#list()
*/
protected List<E> list(Query<E> query) throws HibernateException {
return requireNonNull(query).list();
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testNarrow() throws Exception {
Session s = openSession();
Transaction t = s.beginTransaction();
s.createQuery("from E e join e.reverse as b where b.count=1").list();
s.createQuery("from E e join e.as as b where b.count=1").list();
t.commit();
s.close();
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
protected void cleanupTestData() throws Exception {
Session s = openSession();
s.beginTransaction();
List list = s.createQuery( "from java.lang.Object" ).list();
for ( Object obj : list ) {
s.delete( obj );
}
s.getTransaction().commit();
s.close();
}
代码示例来源:origin: hibernate/hibernate-orm
private void assertResultSize(String hql, int size) {
Session session = openSession();
Transaction txn = session.beginTransaction();
assertEquals( size, session.createQuery(hql).list().size() );
txn.commit();
session.close();
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testSimpleCaseStatementFixture() {
Session s = openSession();
Transaction t = s.beginTransaction();
s.createQuery( "select case p.name when 'Steve' then 'x' else 'y' end from Person p" )
.list();
t.commit();
s.close();
}
代码示例来源:origin: hibernate/hibernate-orm
@SuppressWarnings("unchecked")
private List<DestinationEntity> findDestinationByIds(List<Integer> ids) {
Session session = openSession();
List<DestinationEntity> list = session
.createQuery( "from DestinationEntity de where de.id in (:ids) order by id" )
.setParameterList( "ids", ids ).list();
session.close();
return list;
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testUsageInSelect() {
Session s = openSession();
s.createQuery( "select I from Item i" ).list();
s.close();
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testUsageInJpaInCollectionSyntax() {
Session s = openSession();
s.createQuery( "SELECT DISTINCT object(i) FROM Item I, IN(i.parts) ip where ip.stockNumber = '123'" ).list();
s.close();
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testUsageInDistinct() {
Session s = openSession();
s.createQuery( "select distinct(I) from Item i" ).list();
s.close();
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void basicTest() {
Session s = openSession();
s.createQuery( "select i from Item i where function( 'substring', i.name, 1, 3 ) = 'abc'" )
.list();
s.close();
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testNakedImplicitJoins() {
// note: simply performing syntax and column/table resolution checking in the db
Session s = openSession();
s.beginTransaction();
s.createQuery( "from Animal where mother.father.id = 1" ).list();
s.getTransaction().commit();
s.close();
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testJdkEnumStyleEnumConstant() throws Exception {
Session s = openSession();
s.beginTransaction();
s.createQuery( "from Zoo z where z.classification = org.hibernate.test.hql.Classification.LAME" ).list();
s.getTransaction().commit();
s.close();
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testSimpleCaseStatementWithParamResult() {
Session s = openSession();
Transaction t = s.beginTransaction();
s.createQuery( "select case p.name when 'Steve' then :opt1 else p.name end from Person p" )
.setString( "opt1", "x" )
.list();
t.commit();
s.close();
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
@TestForIssue( jiraKey = "HHH-1689, SQM-30" )
public void testSubQueryAsCaseElseResultExpression() {
final String query = "SELECT CASE WHEN l.id > 1 THEN 1 ELSE (SELECT COUNT(r.id) FROM Root r) END FROM Leaf l";
// simple syntax check
Session s = openSession();
s.beginTransaction();
s.createQuery( query ).list();
s.getTransaction().commit();
s.close();
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
@TestForIssue( jiraKey = "HHH-1689, SQM-30" )
public void testSubQueryAsSimpleCaseWhenExpression() {
final String query = "SELECT CASE l.id WHEN (SELECT COUNT(r.id) FROM Root r) THEN 1 ELSE 0 END FROM Leaf l";
// simple syntax check
Session s = openSession();
s.beginTransaction();
s.createQuery( query ).list();
s.getTransaction().commit();
s.close();
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
@FailureExpected( jiraKey = "HHH-4883")
public void testJoinAcrossEmbedded() {
// NOTE : this may or may not work now with HHH-4883 fixed,
// but i cannot do this checking until HHH-4599 is done.
Session session = openSession();
session.beginTransaction();
session.createQuery( "from Person p join p.name.aliases a where a.source = 'FBI'" )
.list();
session.getTransaction().commit();
session.close();
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
@TestForIssue(jiraKey = "HHH-13084")
public void testHql() {
doInHibernate( this::sessionFactory, session -> {
assertEquals( 1, session.createQuery( "from Person p where p.id is null", Person.class ).list().size() );
assertEquals( 2, session.createQuery( "from Person p where p.id is not null", Person.class ).list().size() );
assertEquals( 3L, session.createQuery( "select count( p ) from Person p" ).uniqueResult() );
} );
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testEntityPropertySelect() throws Exception {
createTestBaseData();
Session session = openSession();
Transaction t = session.beginTransaction();
List results = session.createQuery( "select a.mother from Animal as a" ).list();
assertTrue( "Incorrect result return type", results.get( 0 ) instanceof Animal );
t.commit();
session.close();
destroyTestBaseData();
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
@TestForIssue(jiraKey = "HHH-13084")
public void testHql() {
doInHibernate( this::sessionFactory, session -> {
assertEquals( 2, session.createQuery( "from Person p where p.id = 0", Person.class ).list().size() );
assertEquals( 3L, session.createQuery( "select count( p ) from Person p" ).uniqueResult() );
} );
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testPaginationWithHQL() {
doInHibernate( this::sessionFactory, session -> {
for ( int i = 20; i < 30; i++ ) {
session.persist( new Product2( i, "Kit" + i ) );
}
session.flush();
session.clear();
List list = session.createQuery( "from Product2 order by id" ).setFirstResult( 3 ).setMaxResults( 2 ).list();
assertEquals( Arrays.asList( new Product2( 23, "Kit23" ), new Product2( 24, "Kit24" ) ), list );
} );
}
内容来源于网络,如有侵权,请联系作者删除!