本文整理匯總了Java中org.hibernate.Query.list方法的典型用法代碼示例。如果您正苦於以下問題:Java Query.list方法的具體用法?Java Query.list怎麽用?Java Query.list使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.hibernate.Query
的用法示例。
在下文中一共展示了Query.list方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: loadDataUsingParent
import org.hibernate.Query; //導入方法依賴的package包/類
@Override
public void loadDataUsingParent() {
Session ses=null;
Query query=null;
List<Department> list=null;
List<Employee> emplist=null;
//get Session
ses=HibernateUtil.getSession();
//create Query obj
query=ses.createQuery("from Employee");
//execute Query
emplist=query.list();
//process the Results
for(Employee emp:emplist){
System.out.println("Child---->"+emp);
//get all childs of each parent
Department dept=emp.getDept();
System.out.println("Parent--->"+dept);
/*for(PhoneNumber ph:childs){
}//for
*/
}//for
}
開發者ID:pratikdimble,項目名稱:Hibernate_Association_Mapping_ManyToOne_Save_Load_Maven,代碼行數:26,代碼來源:MTO_DAOImpl.java
示例2: getStatsMarksForLeaders
import org.hibernate.Query; //導入方法依賴的package包/類
@SuppressWarnings("rawtypes")
@Override
public Object[] getStatsMarksForLeaders(Long toolContentId) {
Query query = getSession().createSQLQuery(FIND_MARK_STATS_FOR_LEADERS)
.addScalar("min_grade", FloatType.INSTANCE)
.addScalar("avg_grade", FloatType.INSTANCE)
.addScalar("max_grade", FloatType.INSTANCE)
.addScalar("num_complete", IntegerType.INSTANCE);
query.setLong("toolContentId", toolContentId);
List list = query.list();
if ((list == null) || (list.size() == 0)) {
return null;
} else {
return (Object[]) list.get(0);
}
}
示例3: executeHQLQuery
import org.hibernate.Query; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public List<T> executeHQLQuery(final String hql,
final List<SQLVisitor.SQLVisitorParameter> parameters,
final int skip, final int top)
{
Session session = getSessionFactory().getCurrentSession();
Query query = session.createQuery(hql);
for (int i = 0; i < parameters.size(); i++)
{
SQLVisitor.SQLVisitorParameter param = parameters.get(i);
query.setParameter(i, param.getValue(), param.getType());
}
if (skip > -1)
{
query.setFirstResult(skip);
}
if (top > -1)
{
query.setMaxResults(top);
}
query.setReadOnly(true);
return (List<T>) query.list();
}
示例4: findLastNChanges
import org.hibernate.Query; //導入方法依賴的package包/類
public static List findLastNChanges(Object object, Source source, int n) {
try {
Number objectUniqueId = (Number)object.getClass().getMethod("getUniqueId", new Class[]{}).invoke(object, new Object[]{});
String objectType = object.getClass().getName();
org.hibernate.Session hibSession = new ChangeLogDAO().getSession();
Query q = hibSession.createQuery(
"select ch from ChangeLog ch " +
"where ch.objectUniqueId=:objectUniqueId and ch.objectType=:objectType "+
(source==null?"":"and ch.sourceString=:source ") +
"order by ch.timeStamp desc");
q.setLong("objectUniqueId", objectUniqueId.longValue());
q.setString("objectType",objectType);
if (source!=null)
q.setString("source",source.name());
q.setMaxResults(n);
q.setCacheable(true);
return q.list();
} catch (Exception e) {
Debug.error(e);
}
return null;
}
示例5: geTasksOfUnfinished
import org.hibernate.Query; //導入方法依賴的package包/類
/**
* 獲取該用戶未提交或者未完成的任務
*/
@Override
public List<Task> geTasksOfUnfinished(int user_id,int start,int num) {
List<Task> tasks = new ArrayList<Task>();
Session session = HibernateUtils.getSession();//生成Session實例
Transaction tx = session.beginTransaction();//生成事務實例
try {
Query query = session.createQuery("SELECT new Task( task_id,task_img_amount,task_start_time,user_id) FROM Task WHERE task_iscommit = 0 AND user_id = "+user_id);
query.setFirstResult(start-1);
query.setMaxResults(num);
tasks = query.list();
tx.commit();//提交事務
} catch (Exception e) {
e.printStackTrace();
tx.rollback();//事務回滾
}finally{
HibernateUtils.closeSession();//關閉session實例
}
return tasks;
}
示例6: randomlistObj
import org.hibernate.Query; //導入方法依賴的package包/類
/**
* 隨機取size條記錄
*
* @param <T> 要查詢的實體類
*
* @param target 要查詢的實體類
* @param size 記錄數
* @param where 查詢條件
*
* @return 查詢到的記錄
*/
@SuppressWarnings("unchecked")
public final static <T> List<T> randomlistObj(Class<T> target,int size,Map<String, Object> where){
try {
List<String> randList = new ArrayList<String>(1);
randList.add("RAND()");
StringBuffer hql = getSelectHql(target, where, null, null);
hql.append(" order by RAND()");
Query query = createQuery(where,hql);
faging(size,1, query);
return query.list();
} catch (Exception e) {
setException(e);
return null;
}finally{
closeSession();
}
}
示例7: getAll
import org.hibernate.Query; //導入方法依賴的package包/類
public List<T> getAll(String namedQuery) throws SQLException {
logger.info("Init abstract GetAll to: " + namedQuery);
Session session = HibernateUtil.getSessionFactory().openSession();
List<T> list = null;
try {
session.beginTransaction();
Query query = session.getNamedQuery(namedQuery);
list = (List<T>) query.list();
session.getTransaction().commit();
} catch (HibernateException hibernateException) {
session.getTransaction().rollback();
throw new SQLException(hibernateException);
} finally {
session.close();
}
return list;
}
示例8: findByExample
import org.hibernate.Query; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public List<User> findByExample(User user) {
List<User> users = null;
Session session = sessionFactory.getCurrentSession();
try {
session.beginTransaction();
Query query = session.createQuery("from User where name=:name and age=:age");
query.setProperties(user);
query.setProperties(user);
users = (List<User>) query.list();
session.getTransaction().commit();
} catch (RuntimeException e) {
session.getTransaction().rollback();
}
return users;
}
示例9: get
import org.hibernate.Query; //導入方法依賴的package包/類
@Override
public StatusBean get(String id) {
if (id == null) {
return null;
}
String hql = "FROM StatusBean WHERE id = :id";
Session session = sessionFactory.getCurrentSession();
Query query = session.createQuery(hql);
query.setString("id", id);
List list = query.list();
if (list != null && !list.isEmpty()) {
return (StatusBean) list.get(0);
}
return null;
}
示例10: findPage
import org.hibernate.Query; //導入方法依賴的package包/類
@Override
public Page<T> findPage(final PageRequest pageRequest, String hql, final Object... values) {
AssertUtils.notNull(pageRequest, "pageRequest不能為空");
Page<T> page = new Page<T>(pageRequest);
if (pageRequest.isCountTotal()) {
long totalCount = countHqlResult(hql, values);
page.setTotalItems(totalCount);
}
if (pageRequest.isOrderBySetted()) {
hql = setOrderParameterToHql(hql, pageRequest);
}
Query q = createQuery(hql, values);
setPageParameterToQuery(q, pageRequest);
List result = q.list();
page.setResult(result);
return page;
}
示例11: geTasksOfUnconfirmed
import org.hibernate.Query; //導入方法依賴的package包/類
/**
* 獲取user_id對應的已提交的Task
*/
@Override
public List<Task> geTasksOfUnconfirmed(int user_id,int start,int num) {
List<Task> tasks = new ArrayList<Task>();
Session session = HibernateUtils.getSession();//生成Session實例
Transaction tx = session.beginTransaction();//生成事務實例
try {
Query query = session.createQuery("SELECT new Task( task_id,task_img_amount,task_start_time,user_id) FROM Task WHERE task_iscommit = 1 AND user_id = "+user_id);
query.setFirstResult(start-1);
query.setMaxResults(num);
tasks = query.list();
tx.commit();//提交事務
} catch (Exception e) {
e.printStackTrace();
tx.rollback();//事務回滾
}finally{
HibernateUtils.closeSession();//關閉session實例
}
return tasks;
}
示例12: getStaffByDept
import org.hibernate.Query; //導入方法依賴的package包/類
/**
*
* @param deptCode
* @return
*/
public static List getStaffByDept(String deptCode, Long acadSessionId) throws Exception {
if (deptCode == null){
return(null);
}
Query q = StaffDAO.getInstance().getSession().createQuery(
"select distinct s from Staff s where s.dept=:deptCode and " +
"(select di.externalUniqueId from DepartmentalInstructor di " +
"where di.department.deptCode=:deptCode and di.department.session.uniqueId=:sessionId and di.externalUniqueId = s.externalUniqueId ) is null");
q.setString("deptCode", deptCode);
q.setLong("sessionId", acadSessionId);
q.setCacheable(true);
return (q.list());
}
示例13: getPreviewLessons
import org.hibernate.Query; //導入方法依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public List<Long> getPreviewLessons(Integer limit) {
Query query = getSession().createQuery(FIND_PREVIEW_LESSON_IDS);
if (limit != null) {
query.setMaxResults(limit);
}
return query.list();
}
示例14: find
import org.hibernate.Query; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
protected List<T> find(String hql, Object... params) {
Query query = getSessionFactory().getCurrentSession().createQuery(hql);
for (int i = 0, len = params.length; i < len; i++) {
query.setParameter(i + "", params[i]);
}
return query.list();
}
示例15:
import org.hibernate.Query; //導入方法依賴的package包/類
@Override
public User getUserByName$Pw(String username, String password) {
String sql = "from User where username=:username and password=:password";
Session session = sessionFactory.getCurrentSession();
Query query = session.createQuery(sql);
query.setString("username", username);
query.setString("password", password);
List<User> users = query.list();
if(users.size() == 0) {
return null;
}
return users.get(0);
}