日期:2014-05-20 浏览次数:20768 次
public List<Object[]> findUser() { final String HQL = "select u.userId,u.userName ,u.userPassword from User u"; return (List<Object[]>) getJpaTemplate().execute(new JpaCallback() { public Object doInJpa(EntityManager em) throws PersistenceException { Query query = em.createQuery(HQL); List<Object[]> list = query.getResultList(); return list; } });
public Integer bulkUpdate(final PK[] ids,String propertyName,final Object propertyValue){ final String sqlString = "update "+getEntityName(this.persistentClass)+ " set "+ propertyName +" = :value "+ " where id in (:ids) "; Integer count=hibernateTemplate.execute(new HibernateCallback<Integer>() { public Integer doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.createQuery(sqlString); query.setParameter("value", propertyValue); query.setParameterList("ids", ids); return query.executeUpdate(); } }); return count; }