當前位置: 首頁>>代碼示例>>Java>>正文


Java Query.list方法代碼示例

本文整理匯總了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);
}
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:AssessmentUserDAOHibernate.java

示例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();
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:25,代碼來源:HibernateDao.java

示例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;
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:23,代碼來源:ChangeLog.java

示例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;  
}
 
開發者ID:codekongs,項目名稱:ImageClassify,代碼行數:23,代碼來源:TaskService.java

示例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();
	}
}
 
開發者ID:battlesteed,項目名稱:hibernateMaster,代碼行數:29,代碼來源:DaoUtil.java

示例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;
}
 
開發者ID:mrh3nry,項目名稱:Celebino,代碼行數:24,代碼來源:GenericDao.java

示例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;
}
 
開發者ID:lf23617358,項目名稱:training-sample,代碼行數:18,代碼來源:HibernateUserDao.java

示例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;
}
 
開發者ID:by-syk,項目名稱:SchTtableServer,代碼行數:18,代碼來源:StatusDaoImpl.java

示例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;
}
 
開發者ID:wkeyuan,項目名稱:DWSurvey,代碼行數:23,代碼來源:HibernateDao.java

示例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; 
}
 
開發者ID:codekongs,項目名稱:ImageClassify,代碼行數:24,代碼來源:TaskService.java

示例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());
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:20,代碼來源:Staff.java

示例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();
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:10,代碼來源:LessonDAO.java

示例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();
}
 
開發者ID:CongBao,項目名稱:baozijuan.com,代碼行數:9,代碼來源:BaseDaoHibernate.java

示例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);
}
 
開發者ID:zhangjikai,項目名稱:sdudoc,代碼行數:14,代碼來源:UserDaoImpl.java


注:本文中的org.hibernate.Query.list方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。