Example usage for org.hibernate Query setParameter

List of usage examples for org.hibernate Query setParameter

Introduction

In this page you can find the example usage for org.hibernate Query setParameter.

Prototype

@SuppressWarnings("unchecked")
Query<R> setParameter(int position, Object val);

Source Link

Document

Bind a positional query parameter using its inferred Type.

Usage

From source file:cgi.lemans.portail.domaine.gamaweb.impl.OrdreDeTravailDao.java

@Override
public List<OrdreDeTravail> findIdDemandePlanning(String id) {
    String hql = "from OrdreDeTravail a "

            + "where a.chargeRestante != 0" + "and a.idDemande.idDemande = :id";
    Query query = getSession().createQuery(hql);

    query.setParameter("id", id);

    List<OrdreDeTravail> results = query.list();
    return results;
}

From source file:cgi.lemans.portail.domaine.gamaweb.impl.RessourceTmaDao.java

@Override
public List<RessourceTma> findQuiEquipe(String tag) {
    String hql = "from RessourceTma a " + "where a.tags " + "like :tag";
    Query query = getSession().createQuery(hql);
    query.setParameter("tag", tag);
    System.out.println(query.getQueryString());

    List<RessourceTma> results = query.list();
    return results;

}

From source file:ch.algotrader.dao.AbstractDao.java

License:Open Source License

private void applyParameters(final Query query, final Object... params) {
    for (int i = 0; i < params.length; i++) {
        query.setParameter(i, params[i]);
    }/* ww  w.ja va2  s .  com*/
}

From source file:ch.algotrader.dao.AbstractDao.java

License:Open Source License

private void applyParameters(final Query query, final NamedParam... params) {
    for (NamedParam param : params) {
        if (param.getValue() instanceof Collection) {
            query.setParameterList(param.getName(), (Collection<?>) param.getValue());
        } else {/* w  w w . j  av  a 2 s . c o  m*/
            query.setParameter(param.getName(), param.getValue());
        }
    }
}

From source file:ch.algotrader.dao.AbstractDao.java

License:Open Source License

public boolean deleteById(final long id) {

    Session currentSession = getCurrentSession();
    Query query = currentSession
            .createQuery("delete from " + this.entityClass.getSimpleName() + " where id = :id");
    query.setParameter("id", id);
    int result = query.executeUpdate();
    if (result > 0) {

        // Need to clear the session to ensure deleted entities are not stuck in the session cache
        currentSession.clear();/*w w  w.ja v a  2s.  c o  m*/
        return true;
    } else {

        return false;
    }
}

From source file:ch.astina.hesperid.dao.hibernate.ObserverDAOHibernate.java

License:Apache License

@SuppressWarnings("unchecked")
@Override//from  w  ww.  j  a  v  a2  s  .c o m
public List<Observer> getClientObservers() {
    Query query = session.createQuery(
            "from Observer o " + "where o.observerStrategy.observationScope = :scope " + "order by o.name");
    query.setParameter("scope", ObservationScope.CLIENT);
    return query.list();
}

From source file:ch.astina.hesperid.dao.hibernate.ObserverDAOHibernate.java

License:Apache License

@SuppressWarnings("unchecked")
@Override//from   www .  j a  v  a  2  s. com
public List<Observer> getClientObservers(Asset asset) {
    Query query = session.createQuery("from Observer o " + "where o.observerStrategy.observationScope = :scope "
            + "and o.asset = :asset order by o.name");
    query.setParameter("scope", ObservationScope.CLIENT);
    query.setEntity("asset", asset);
    return query.list();
}

From source file:ch.astina.hesperid.dao.hibernate.ObserverDAOHibernate.java

License:Apache License

@SuppressWarnings("unchecked")
@Override/*from  ww w . jav a2  s.c o  m*/
public List<Observer> getExternalObservers() {
    Query query = session.createQuery(
            "from Observer o " + "where o.observerStrategy.observationScope = :scope " + "order by o.name");
    query.setParameter("scope", ObservationScope.EXTERNAL);
    return query.list();
}

From source file:ch.astina.hesperid.dao.hibernate.ObserverDAOHibernate.java

License:Apache License

@SuppressWarnings("unchecked")
@Override/* w w w  .j a v a  2 s .  com*/
public List<Observer> getExternalObservers(Asset asset) {
    Query query = session.createQuery("from Observer o " + "where o.observerStrategy.observationScope = :scope "
            + "and o.asset = :asset order by o.name");
    query.setParameter("scope", ObservationScope.EXTERNAL);
    query.setEntity("asset", asset);
    return query.list();
}

From source file:ch.eggbacon.app.service.LeistungServiceImpl.java

License:Open Source License

@Override
public Leistung getLeistungByBeschreibung(String beschreibung) {
    Query q = getSession().createQuery("FROM " + TABLE_NAME + " WHERE Beschreibung = :beschr");
    q.setParameter("beschr", beschreibung);
    return ((Leistung) q.uniqueResult());
}