本文整理了Java中org.hibernate.Criteria.setResultTransformer()
方法的一些代码示例,展示了Criteria.setResultTransformer()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Criteria.setResultTransformer()
方法的具体详情如下:
包路径:org.hibernate.Criteria
类名称:Criteria
方法名:setResultTransformer
[英]Set a strategy for handling the query results. This determines the "shape" of the query result.
[中]设置处理查询结果的策略。这决定了查询结果的“形状”。
代码示例来源:origin: hibernate/hibernate-orm
/**
* Set the result transformer to use.
*
* @param resultTransformer The result transformer to use
*
* @return {@code this}, for method chaining
*/
public DetachedCriteria setResultTransformer(ResultTransformer resultTransformer) {
criteria.setResultTransformer( resultTransformer );
return this;
}
代码示例来源: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: hibernate/hibernate-orm
protected Criteria getCriteria(Session s) {
return s.createCriteria( Student.class, "s" )
.createAlias( "s.preferredCourse", "pc", Criteria.LEFT_JOIN )
.setFetchMode( "enrolments", FetchMode.JOIN )
.setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP );
}
};
代码示例来源:origin: hibernate/hibernate-orm
@Override
protected Criteria getCriteria(Session s) {
return s.createCriteria( Student.class, "s" )
.createAlias( "s.addresses", "a", CriteriaSpecification.LEFT_JOIN )
.setResultTransformer( CriteriaSpecification.ALIAS_TO_ENTITY_MAP )
.createCriteria( "s.preferredCourse", CriteriaSpecification.INNER_JOIN )
.addOrder( Order.asc( "s.studentNumber") );
}
};
代码示例来源:origin: hibernate/hibernate-orm
@Override
protected Criteria getCriteria(Session s) {
return s.createCriteria( Student.class, "s" )
.createAlias( "s.enrolments", "e", CriteriaSpecification.LEFT_JOIN )
.createAlias( "e.course", "c", CriteriaSpecification.LEFT_JOIN )
.setResultTransformer( CriteriaSpecification.ALIAS_TO_ENTITY_MAP )
.addOrder( Order.asc( "s.studentNumber") );
}
};
代码示例来源:origin: hibernate/hibernate-orm
@Override
protected Criteria getCriteria(Session s) {
return s.createCriteria( Student.class, "s" )
.createAlias( "s.preferredCourse", "p", CriteriaSpecification.LEFT_JOIN )
.createAlias( "s.addresses", "a", CriteriaSpecification.LEFT_JOIN )
.setResultTransformer( CriteriaSpecification.ALIAS_TO_ENTITY_MAP )
.addOrder( Order.asc( "s.studentNumber" ) );
}
};
代码示例来源:origin: hibernate/hibernate-orm
protected Criteria getCriteria(Session s) {
return s.createCriteria( Student.class, "s" )
.createAlias( "s.preferredCourse", "pc", Criteria.LEFT_JOIN )
.setFetchMode( "enrolments", FetchMode.JOIN )
.addOrder( Order.asc( "s.studentNumber" ))
.setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP );
}
};
代码示例来源:origin: hibernate/hibernate-orm
protected Criteria getCriteria(Session s) {
return s.createCriteria( Enrolment.class, "e" )
.setProjection( Projections.property( "e.student" ).as( "student" ) )
.addOrder( Order.asc( "e.studentNumber") )
.setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP );
}
};
代码示例来源:origin: hibernate/hibernate-orm
protected Criteria getCriteria(Session s) throws Exception {
return s.createCriteria( Student.class, "s" )
.setProjection( Projections.property( "s.name" ) )
.addOrder( Order.asc( "s.studentNumber" ) )
.setResultTransformer( new AliasToBeanConstructorResultTransformer( getConstructor() ) );
}
private Constructor getConstructor() throws NoSuchMethodException {
代码示例来源:origin: hibernate/hibernate-orm
protected Criteria getCriteria(Session s) throws Exception {
return s.createCriteria( Student.class, "s" )
.setProjection( Projections.property( "s.name" ).as( "name" ))
.addOrder( Order.asc( "s.studentNumber" ) )
.setResultTransformer( new AliasToBeanConstructorResultTransformer( getConstructor() ) );
}
private Constructor getConstructor() throws NoSuchMethodException {
代码示例来源:origin: hibernate/hibernate-orm
protected Criteria getCriteria(Session s) {
return s.createCriteria( Enrolment.class )
.setProjection(
Projections.projectionList()
.add( Projections.min( "studentNumber" ).as( "minStudentNumber" ) )
.add( Projections.max( "studentNumber" ).as( "maxStudentNumber" ) )
)
.setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP );
}
};
代码示例来源:origin: hibernate/hibernate-orm
protected Criteria getCriteria(Session s) {
return s.createCriteria( Enrolment.class, "e" )
.createAlias( "e.student", "st" )
.createAlias( "e.course", "co" )
.setProjection( Projections.property( "st.name" ).as( "studentName" ) )
.addOrder( Order.asc( "st.studentNumber" ) )
.setResultTransformer( Transformers.aliasToBean( StudentDTO.class ) );
}
};
代码示例来源:origin: hibernate/hibernate-orm
protected Criteria getCriteria(Session s) {
return s.createCriteria( Student.class, "s" )
.setProjection(
Projections.projectionList()
.add( Property.forName( "s.studentNumber" ).as( "sNumber" ) )
.add( Property.forName( "s.name" ).as( "sName" ) )
)
.addOrder( Order.asc( "s.studentNumber" ) )
.setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP );
}
};
代码示例来源:origin: hibernate/hibernate-orm
protected Criteria getCriteria(Session s) {
return s.createCriteria( Student.class, "s" )
.setProjection(
Projections.projectionList()
.add( Property.forName( "s.studentNumber" ).as( "sNumber" ) )
.add( Property.forName( "s.name" ).as( "sName" ) )
)
.addOrder( Order.asc( "s.studentNumber" ) )
.setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP );
}
};
代码示例来源:origin: hibernate/hibernate-orm
protected Criteria getCriteria(Session s) {
return s.createCriteria( Student.class, "s" )
.setProjection(
Projections.projectionList()
.add( Property.forName( "s.studentNumber" ).as( "studentNumber" ))
.add( Property.forName( "s.name" ).as( "name" ) )
)
.addOrder( Order.asc( "s.studentNumber" ) )
.setResultTransformer( Transformers.TO_LIST );
}
};
代码示例来源:origin: hibernate/hibernate-orm
protected Criteria getCriteria(Session s) throws Exception {
return s.createCriteria( Student.class, "s" )
.setProjection(
Projections.projectionList()
.add( Projections.sqlProjection( "555 as studentNumber", new String[]{ "studentNumber" }, new Type[] { StandardBasicTypes.LONG } ) )
.add( Property.forName( "s.name" ).as( "name" ) )
)
.addOrder( Order.asc( "s.studentNumber" ) )
.setResultTransformer( new AliasToBeanConstructorResultTransformer( getConstructor() ) );
}
private Constructor getConstructor() throws NoSuchMethodException {
代码示例来源:origin: hibernate/hibernate-orm
protected Criteria getCriteria(Session s) throws Exception {
return s.createCriteria( Student.class, "s" )
.setProjection(
Projections.projectionList()
.add( Property.forName( "s.studentNumber" ).as( "studentNumber" ))
.add( Property.forName( "s.name" ).as( "name" ))
)
.addOrder( Order.asc( "s.studentNumber" ) )
.setResultTransformer( new AliasToBeanConstructorResultTransformer( getConstructor() ) );
}
private Constructor getConstructor() throws NoSuchMethodException {
代码示例来源:origin: hibernate/hibernate-orm
protected Criteria getCriteria(Session s) {
return s.createCriteria( Student.class, "s" )
.setProjection(
Projections.projectionList()
.add( Property.forName( "s.studentNumber" ).as( "studentNumber" ) )
.add( Property.forName( "s.name" ).as( "name" ) )
)
.addOrder( Order.asc( "s.studentNumber" ) )
.setResultTransformer( new AliasToBeanConstructorResultTransformer( getConstructor() ) );
}
private Constructor getConstructor() {
代码示例来源:origin: hibernate/hibernate-orm
protected Criteria getCriteria(Session s) {
return s.createCriteria( Enrolment.class, "e" )
.setProjection(
Projections.projectionList()
.add( Property.forName( "e.student" ), "student" )
.add( Property.forName( "e.semester" ), "semester" )
.add( Property.forName( "e.year" ), "year" )
.add( Property.forName( "e.course" ), "course" )
)
.addOrder( Order.asc( "studentNumber") )
.setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP );
}
};
代码示例来源:origin: hibernate/hibernate-orm
protected Criteria getCriteria(Session s) {
return s.createCriteria( Enrolment.class, "e" )
.createAlias( "e.student", "st" )
.createAlias( "e.course", "co" )
.setProjection(
Projections.projectionList()
.add( Property.forName( "st.name" ).as( "studentName" ) )
.add( Property.forName( "co.description" ).as( "courseDescription" ) )
)
.addOrder( Order.asc( "e.studentNumber" ) )
.setResultTransformer( Transformers.aliasToBean( StudentDTO.class ) );
}
};
内容来源于网络,如有侵权,请联系作者删除!