本文整理了Java中org.hibernate.Criteria.list()
方法的一些代码示例,展示了Criteria.list()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Criteria.list()
方法的具体详情如下:
包路径:org.hibernate.Criteria
类名称:Criteria
方法名:list
[英]Get the results.
[中]得到结果。
代码示例来源:origin: stackoverflow.com
Criteria c = session.createCriteria(Cat.class);
c.createAlias("mother.kind", "motherKind");
c.addOrder(Order.asc("motherKind.value"));
return c.list();
代码示例来源:origin: stackoverflow.com
Criteria c = session.createCriteria(CountryDTO.class);
c.add(Restrictions.eq("type", type));
c.add(status == null ? Restrictions.isNull("status") : Restrictions.eq("status", status));
List result = c.list();
代码示例来源:origin: kaaproject/kaa
/**
* Check if authority exists.
*
* @param authority the authority
* @return true if authority exists
*/
public boolean isAuthorityExists(String authority) {
Criteria criteria = getSession().createCriteria(Authority.class);
criteria.add(Restrictions.eq(AUTHORITY_PROPERTY, authority));
List<Authority> resultList = criteria.list();
return !resultList.isEmpty();
}
代码示例来源:origin: spring-projects/spring-framework
@Override
@SuppressWarnings({"unchecked", "deprecation"})
public <T> List<T> findByExample(
@Nullable final String entityName, final T exampleEntity, final int firstResult, final int maxResults)
throws DataAccessException {
Assert.notNull(exampleEntity, "Example entity must not be null");
return nonNull(executeWithNativeSession((HibernateCallback<List<T>>) session -> {
Criteria executableCriteria = (entityName != null ?
session.createCriteria(entityName) : session.createCriteria(exampleEntity.getClass()));
executableCriteria.add(Example.create(exampleEntity));
prepareCriteria(executableCriteria);
if (firstResult >= 0) {
executableCriteria.setFirstResult(firstResult);
}
if (maxResults > 0) {
executableCriteria.setMaxResults(maxResults);
}
return executableCriteria.list();
}));
}
代码示例来源:origin: gocd/gocd
public ServerBackup lastBackup() {
List results = (List) getHibernateTemplate().execute((HibernateCallback) session -> {
Criteria criteria = session.createCriteria(ServerBackup.class);
criteria.setMaxResults(1);
criteria.addOrder(Order.desc("id"));
return criteria.list();
});
return results.isEmpty() ? null : (ServerBackup) results.get(0);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
@SuppressWarnings({"unchecked", "deprecation"})
public <T> List<T> loadAll(final Class<T> entityClass) throws DataAccessException {
return nonNull(executeWithNativeSession((HibernateCallback<List<T>>) session -> {
Criteria criteria = session.createCriteria(entityClass);
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
prepareCriteria(criteria);
return criteria.list();
}));
}
代码示例来源:origin: stackoverflow.com
return (T) sessionFactory.getCurrentSession().save(o);
sessionFactory.getCurrentSession().delete(object);
return (T) sessionFactory.getCurrentSession().get(type, id);
final Session session = sessionFactory.getCurrentSession();
final Criteria crit = session.createCriteria(type);
return crit.list();
代码示例来源:origin: hibernate/hibernate-orm
.setFetchMode("baz", FetchMode.SELECT)
.setFetchMode("abstracts", FetchMode.JOIN)
.list();
assertTrue( list.size() == 1 && list.get( 0 ) == f );
.list();
assertTrue( list.size() == 1 && list.get( 0 ) == f );
.list();
assertTrue(
"Example API without like did not work correctly, size was " + list.size(),
.list();
assertTrue( "Example API without like did not work correctly, size was " + list.size(), list.size()==1 && list.get(0)==f );
.list();
.addOrder( Order.asc("date") )
.list();
.addOrder( Order.asc("date") )
.addOrder( Order.desc("string") )
.list();
.list();
assertTrue( list.size() == 3 );
.setFetchMode( "component.importantDates", FetchMode.JOIN )
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
代码示例来源:origin: hibernate/hibernate-orm
List<Object[]> result = session.createCriteria( Category.class, "c" ).createAlias( "products", "p" )
.setProjection(
Projections.projectionList()
.add( Projections.countDistinct( "p.id" ) )
.addOrder( Order.asc( "c.id" ) )
.setFirstResult( 1 ).setMaxResults( 3 ).list();
代码示例来源:origin: kaaproject/kaa
protected List<T> findListByCriterionWithAlias(String path, String alias,
JoinType type, Criterion criterion) {
String className = getSimpleClassName();
LOG.trace("Searching {} entities by criterion [{}] ", className, criterion);
Criteria criteria = getCriteria();
if (type == null) {
criteria.createAlias(path, alias);
} else {
criteria.createAlias(path, alias, type);
}
criteria.add(criterion);
List<T> resultList = criteria.list();
if (resultList == null) {
resultList = Collections.emptyList();
}
return resultList;
}
代码示例来源:origin: hibernate/hibernate-orm
List parents = s.createCriteria(Parent.class)
.add( Property.forName("name").between("bar", "foo") )
.addOrder( Order.desc("name") )
.list();
p = (Parent) parents.get(0);
q = (Parent) parents.get(1);
代码示例来源:origin: hibernate/hibernate-orm
Criteria criteria = session.createCriteria( Seller.class, "s" );
criteria.createCriteria(
"s.soldTo",
"c",
JoinType.INNER_JOIN,
Restrictions.eq( "name", "join-table-customer1" )
);
criteria.setResultTransformer( Criteria.DISTINCT_ROOT_ENTITY );
@SuppressWarnings("unchecked")
List<Seller> results = criteria.list();
assertTrue( results.size() == 1 );
assertTrue( results.contains( seller1 ) );
criteria = session.createCriteria( Seller.class, "s" );
criteria.createCriteria(
"s.soldTo",
"c",
JoinType.INNER_JOIN,
Restrictions.eq( "name", "join-table-customer2" )
);
criteria.setResultTransformer( Criteria.DISTINCT_ROOT_ENTITY );
List<Seller> results2 = criteria.list();
assertTrue( results2.size() == 2 );
assertTrue( results2.contains( seller1 ) );
代码示例来源:origin: stackoverflow.com
Session session = sessionFactory.getCurrentSession();
Integer personID = (Integer) session.save(p);
return personID;
Session session = sessionFactory.getCurrentSession();
Person retrievedPerson = (Person) session.get(Person.class, id);
return retrievedPerson;
Session session = sessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(Person.class);
return criteria.list();
代码示例来源:origin: gocd/gocd
public EnvironmentVariables load(final Long entityId, final EnvironmentVariableType type) {
List<EnvironmentVariable> result = (List<EnvironmentVariable>) transactionTemplate.execute((TransactionCallback) transactionStatus -> {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(EnvironmentVariable.class).add(Restrictions.eq("entityId", entityId)).add(
Restrictions.eq("entityType", type.toString())).addOrder(Order.asc("id"));
criteria.setCacheable(true);
return criteria.list();
});
return new EnvironmentVariables(result);
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testEnablingJoinFetchProfileAgainstSelfReferentialAssociation() {
Session s = openSession();
s.beginTransaction();
s.enableFetchProfile( Employee.FETCH_PROFILE_TREE );
s.createCriteria( Employee.class )
.add( Restrictions.isNull( "manager" ) )
.list();
s.getTransaction().commit();
s.close();
}
}
代码示例来源:origin: hibernate/hibernate-orm
t = s.beginTransaction();
List parents = s.createCriteria(Parent.class)
.createCriteria("moreChildren")
.createCriteria("friends")
.addOrder( Order.desc("name") )
.list();
parents = s.createCriteria(Parent.class)
.setFetchMode("moreChildren", FetchMode.JOIN)
.setFetchMode("moreChildren.friends", FetchMode.JOIN)
.addOrder( Order.desc("name") )
.list();
代码示例来源:origin: org.springframework/spring-orm
@Override
@SuppressWarnings({"unchecked", "deprecation"})
public <T> List<T> loadAll(final Class<T> entityClass) throws DataAccessException {
return nonNull(executeWithNativeSession((HibernateCallback<List<T>>) session -> {
Criteria criteria = session.createCriteria(entityClass);
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
prepareCriteria(criteria);
return criteria.list();
}));
}
代码示例来源:origin: hibernate/hibernate-orm
/**
* Use a Criteria query - see FORGE-247
*/
public List listEventsWithCriteria() {
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
List result = session.createCriteria(Event.class)
.setCacheable(true)
.list();
session.getTransaction().commit();
return result;
}
代码示例来源:origin: hibernate/hibernate-orm
.createCriteria( Item.class )
.addOrder( org.hibernate.criterion.Order.asc( "this.name" ) )
.createAlias( "this.bids", "i_bid", JoinType.LEFT_OUTER_JOIN )
.setProjection(
Projections.projectionList().add( Projections.property( "this.name" ), "item_name" )
criteria.list();
代码示例来源:origin: stackoverflow.com
public List<PayoutDetails> getPayoutDetails(AdvisorReportForm advisorReportForm) {
Criteria criteria = getSession().createCriteria(PayoutDetails.class);
if (advisorReportForm.getAdvisorId() != null && advisorReportForm.getAdvisorId() > 0) {
criteria.add(Restrictions.eq("advisorId", advisorReportForm.getAdvisorId().toString()));
}
criteria.createAlias("payoutHeader", "header")
.add(Restrictions.between("header.chequeIssuedDate", advisorReportForm.getFromDate(), advisorReportForm.getToDate()));
return criteria.list();
}
内容来源于网络,如有侵权,请联系作者删除!