Example usage for javax.persistence Query getResultList

List of usage examples for javax.persistence Query getResultList

Introduction

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

Prototype

List getResultList();

Source Link

Document

Execute a SELECT query and return the query results as an untyped List.

Usage

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

@Override
@SuppressWarnings("unchecked")
public List<Song> getSongsBySameArtistOrderBySongTitle(Integer songId) {

    Query query = em
            .createQuery("select s2 from Song s1 join s1.artist.songs s2 where s1.id=? order by s2.title");
    query.setParameter(1, songId);//w w  w  .java 2  s .  c  om

    return query.getResultList();
}

From source file:de.berlios.jhelpdesk.dao.jpa.TicketEventDAOJpa.java

public List<TicketEvent> getLastEvents(final int howMuch) {
    return (List<TicketEvent>) this.jpaTemplate.execute(new JpaCallback() {
        public Object doInJpa(EntityManager em) throws PersistenceException {
            Query q = em.createNamedQuery("TicketEvent.getLastFewEventsOrderByEventDateDESC");
            q.setMaxResults(howMuch);//from ww  w .  ja v a 2  s .  c o  m
            return q.getResultList();
        }
    });
}

From source file:org.simbasecurity.core.domain.repository.RuleDatabaseRepository.java

@SuppressWarnings("unchecked")
public Collection<URLRule> findURLRules(String username) {
    Query query1 = entityManager.createQuery(QUERY_URL_RULES_FOR_USER).setParameter(USERNAME, username);
    Collection<URLRule> result = query1.getResultList();
    Query query = entityManager.createQuery(QUERY_URL_RULES_FOR_GROUPUSER).setParameter(USERNAME, username);
    result.addAll(query.getResultList());
    return result;
}

From source file:com.expressui.sample.dao.CountryDao.java

public List<Country> findCountriesWithStates() {
    Query query = getEntityManager()
            .createQuery("SELECT DISTINCT c FROM Country c, State s WHERE s.country = c ORDER BY c.name");
    setReadOnly(query);/* w  w w .  ja  v a 2  s  . c  o  m*/

    return query.getResultList();
}

From source file:com.plan.proyecto.repositorios.DaoContenidoImpl.java

@Override
public List<Contenido> findComentariosoByMensaje(Contenido mensaje) {

    if (mensaje == null) {
        return null;
    }/* w w  w.  j av  a  2  s  . c om*/

    Query query = em.createNamedQuery("Contenido.findComentariosByMensaje");
    query.setParameter("idValor", mensaje.getId());

    return query.getResultList();
}

From source file:com.srinathavan.mwbng.core.repositories.jpa.JpaBlogRepo.java

@Override
public List<Blog> findBlogsByAccount(Long accountId) {
    Query query = em.createQuery("Select b from Blog b where b.owner.id=?");
    query.setParameter(0, accountId);//from  w w  w .  jav  a 2s  . c om
    return query.getResultList();
}

From source file:DAO.PersonnesStatutsDAOImpl.java

@Transactional(readOnly = true)
@Override/*from ww  w .  ja  v a  2 s  .co  m*/
public List<PersonnesStatutsEntity> findAll() {
    Query q = em.createQuery("SELECT ps FROM PersonnesStatutsEntity ps");
    return q.getResultList();
}

From source file:de.berlios.jhelpdesk.dao.jpa.ArticleDAOJpa.java

public List<Article> getLastArticles(final int howMuch) {
    try {//  ww  w.j  a  v a  2s . com
        return (List<Article>) this.jpaTemplate.executeFind(new JpaCallback() {
            public Object doInJpa(EntityManager em) throws PersistenceException {
                Query q = em.createNamedQuery("Article.lastAdded");
                q.setMaxResults(howMuch);
                return q.getResultList();
            }
        });
    } catch (Exception ex) {
        log.error("Nie mona pobra ostatnio dodanych artykuw.", ex);
    }
    return Collections.<Article>emptyList();
}

From source file:ispok.dao.CashgameSessionHibernateJpaDao.java

@Override
public List<CashgameSession> getActiveByCashgameId(Long cashgameId) {
    String jpql = "SELECT cs FROM CashgameSession cs WHERE cs.cashgame.id = :id AND cs.stop IS NULL";
    Query query = getEntityManager().createQuery(jpql);
    query.setParameter("id", cashgameId);
    @SuppressWarnings("unchecked")
    List<CashgameSession> cashgameSessions = query.getResultList();
    return cashgameSessions;
}

From source file:com.brienwheeler.svc.usergroups.impl.UserGroupMemberDao.java

@Override
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
@SuppressWarnings("unchecked")
public List<UserGroupMember> findForUser(User user) {
    Query query = entityManager.createQuery("from UserGroupMember where user = :user");
    query.setParameter("user", user);
    return (List<UserGroupMember>) query.getResultList();
}