Example usage for javax.persistence Query setParameter

List of usage examples for javax.persistence Query setParameter

Introduction

In this page you can find the example usage for javax.persistence Query setParameter.

Prototype

Query setParameter(int position, Object value);

Source Link

Document

Bind an argument value to a positional parameter.

Usage

From source file:com.tamnd.app.core.repositories.jpa.AccountRepoImpl.java

@Override
public Account findAccountByName(String name) {
    Query query = em.createQuery("SELECT a FROM Account a WHERE a.userName=?1");
    query.setParameter(1, name);
    List<Account> accounts = query.getResultList();
    if (accounts.isEmpty()) {
        return null;
    } else {/*from   ww  w. j  a  va  2s  .com*/
        return accounts.get(0);
    }
}

From source file:com.tamnd2.basicwebapp.core.repositories.jpa.JpaBlogEntryRepo.java

@Override
public List<BlogEntry> findByBlogId(Long blogId) {
    Query query = em.createQuery("SELECT b FROM BlogEntry b WHERE b.blog.id=?1");
    query.setParameter(1, blogId);
    return query.getResultList();
}

From source file:edu.mum.dao.impl.UserDaoImpl.java

@Override
public List<User> findAllExceptThisUserId(Integer id) {

    Query query = this.entityManager.createQuery("SELECT u FROM User u where u.id!=:id");

    query.setParameter("id", id);

    return query.getResultList();
}

From source file:org.prueba.jpa.UserDao.java

@SuppressWarnings("unchecked")
public List<PersonaEmpresaUsuario> getAll() {
    //return entityManager.createQuery("SELECT p FROM PersonaEmpresaUsuario p WHERE p.ciRuc = '0923746663'").getResultList();
    Query queryByName = entityManager.createNamedQuery("PersonaEmpresaUsuario.findByCiRuc");
    queryByName.setParameter("ciRuc", "0923746663");
    return queryByName.getResultList();
}

From source file:uk.co.threeonefour.ifictionary.web.user.dao.JpaUserDao.java

@Transactional
@Override// w  w  w .ja  v  a 2s  .  co  m
public User findUser(String userId) {
    String query = "SELECT u FROM User AS u WHERE userId=:userId";
    EntityManager em = entityManager;
    Query q = em.createQuery(query.toString());
    q.setParameter("userId", userId);
    try {
        return (User) q.getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}

From source file:com.dhenton9000.birt.jpa.service.impl.EmployeesServiceImpl.java

@Override
public List<Orders> getOrdersForEmployee(Integer employeeId) {
    String qString = "select o " + " from Orders o " + " join  o.customer   cust " + " join  cust.employee   e "
            + " where e.employeeNumber = :id ";

    Query q = entityManager.createQuery(qString);
    q.setParameter("id", employeeId);
    List orders = q.getResultList();
    return orders;
}

From source file:com.tamnd2.basicwebapp.core.repositories.jpa.JpaBlogRepo.java

@Override
public Blog findBlogByTitle(String title) {
    Query query = em.createQuery("SELECT b from Blog b where b.title=?1");
    query.setParameter(1, title);
    List<Blog> blogs = query.getResultList();
    if (blogs.isEmpty()) {
        return null;
    } else {/*from   w ww  . jav a  2 s.com*/
        return blogs.get(0);
    }
}

From source file:org.cleverbus.core.common.dao.MessageOperationDaoJpaImpl.java

@Override
public boolean setCancelState(Message msg) {
    Assert.notNull(msg, "the msg must not be null");

    String jSql = "UPDATE " + Message.class.getName() + " SET state = ?1 "
            + " WHERE msgId = ?2 AND state IN (?3)";

    Query q = em.createQuery(jSql);
    q.setParameter(1, MsgStateEnum.CANCEL);
    q.setParameter(2, msg.getMsgId());//from w  w  w .java  2 s.  c o  m
    q.setParameter(3, Arrays.asList(MsgStateEnum.NEW, MsgStateEnum.PARTLY_FAILED, MsgStateEnum.POSTPONED));

    return q.executeUpdate() > 0;
}

From source file:com.excilys.ebi.sample.jpa.query.benchmark.repository.impl.JPQLRepository.java

@Override
@SuppressWarnings("unchecked")
public List<Song> getSongsByArtistNameOrderBySongTitle(String name) {

    Query query = em.createQuery("from Song where artist.name=? order by title");
    query.setParameter(1, name);

    return query.getResultList();
}

From source file:com.mvcmusic.mvcmusicstore.models.GenreModel.java

@SuppressWarnings("unchecked")
public Genre findGenreById(int passId) {
    List<Genre> genreList = new ArrayList<Genre>();

    try {//from  ww  w  .j a v a 2  s . co  m
        Query q = em.createNamedQuery("Genre.findByGenreid");
        q.setParameter("genreid", passId);
        genreList = q.getResultList();
    } catch (Exception e) {
        System.out.println("ERROR::: " + e);
    }

    return genreList.get(0);
}