List of usage examples for org.hibernate Query setParameter
@SuppressWarnings("unchecked") Query<R> setParameter(int position, Object val);
From source file:agh.musicapplication.mappdao.MUserRepository.java
@Override public MUser findUserByLogin(String login) { Query query = getSession().createQuery("from MUser where login = :login"); query.setParameter("login", login); return (MUser) query.uniqueResult(); }
From source file:agh.musicapplication.mappdao.MUserReviewRepository.java
@Override public Long getCountOfMUserReview(MUser user) { Query query = getSession().createQuery("select count(*) from MUserReview m where m.user=:user"); query.setParameter("user", user); Long count = (Long) query.uniqueResult(); return count; }
From source file:agh.musicapplication.mappdao.MUserVocalistRepository.java
@Override public Long getCountOfMUserVocalist(MUser user) { Query query = getSession().createQuery("select count(*) from MUserVocalist m where m.user=:user"); query.setParameter("user", user); Long count = (Long) query.uniqueResult(); return count; }
From source file:agh.musicapplication.mappdao.MUserVocalistRepository.java
@Override public Double getAvgVocalistRankOfSomeUser(MUser user) { Query query = getSession().createQuery("select avg(m.grade) from MUserVocalist m where m.user=:user"); query.setParameter("user", user); Double average = (Double) query.uniqueResult(); return average; }
From source file:agh.musicapplication.mappdao.MVocalistRepository.java
@Override public MVocalist findVocalistByName(String vocalistArtisticName) { Query query = getSession().createQuery("from MVocalist where artisticName = :vocalistArtisticName"); query.setParameter("vocalistArtisticName", vocalistArtisticName); return (MVocalist) query.uniqueResult(); }
From source file:aish.vaishno.hibernatesample.FoodOrderDao.java
public Integer updateFoodOrder(FoodOrder foodOrder) { // Transaction transaction=session.beginTransaction(); Query query = session.createQuery("update FoodOrder set itemName= :itemName where id= :id"); query.setParameter("itemName", foodOrder.getItemName()); query.setParameter("id", foodOrder.getId()); Integer result = query.executeUpdate(); return result; }
From source file:aish.vaishno.hibernatesample.FoodOrderDao.java
public Integer deleteFoodOrder(FoodOrder foodOrder) { Transaction transaction = session.beginTransaction(); Query query = session.createQuery("delete FoodOrder where id= :id"); // query.setParameter("itemName",foodOrder.getItemName()); query.setParameter("id", foodOrder.getId()); query.setTimeout(50);//from w ww . j a va2s. c o m Integer result = query.executeUpdate(); transaction.commit(); return result; }
From source file:alma.acs.tmcdb.TestPojosPersistence.java
License:Open Source License
public void testHQL() throws Exception { createDB();//from w w w.j a va 2 s . co m try { createConfigurationComputerAndTwoNetworkDevices(); Configuration config = (Configuration) hibernateUtil.getList(Configuration.class).iterator().next(); assertNotNull(config); // Now we test that using HQL queries Query q = hibernateUtil.getSession().createQuery("from NetworkDevice as nd where nd.name = ?"); q.setParameter(0, "wall-e"); assertEquals(2, q.list().size()); q = hibernateUtil.getSession() .createQuery("from NetworkDevice as nd where nd.name = ? and nd.networkName = ?"); q.setParameter(0, "wall-e"); q.setParameter(1, "wall-e.eso.org"); assertEquals(1, q.list().size()); q = hibernateUtil.getSession().createQuery("from NetworkDevice as nd where nd.configuration = ?"); q.setParameter(0, config); assertEquals(3, q.list().size()); q = hibernateUtil.getSession().createQuery( "from Configuration as conf where conf.configurationName = ? and creationTime < ?"); q.setParameter(0, "rtobarConfig"); q.setParameter(1, new Date()); assertEquals(1, q.list().size()); try { // typo: should be configurationName q = hibernateUtil.getSession() .createQuery("from Configuration as conf where conf.configuratioName = ?"); q.setParameter(0, "rtobarConfig"); q.list(); fail("Should fail, property 'configuratioName' doesn't exist for Configuration objects"); } catch (QueryException e) { } } finally { dropDB(); } }
From source file:apm.common.core.DaoImpl.java
License:Open Source License
/** * ?// w w w . ja v a 2s . c o m * @param query * @param parameter */ private void setParameter(Query query, Object... parameter) { if (parameter != null) { for (int i = 0; i < parameter.length; i++) { query.setParameter(i, parameter[i]); } } }
From source file:app.core.Db.java
License:Open Source License
/** * @deprecated use Criteria API instead// w w w. ja v a2 s . c om */ protected static Query createQuery(String hql, Object... params) { Query query = getSession().createQuery(hql); int i = 0; for (Object param : params) { query.setParameter(i++, param); } return query; }