List of usage examples for javax.persistence Query getSingleResult
Object getSingleResult();
From source file:com.healthcit.cacure.dao.ModuleDao.java
public BaseModule getById(Long id) { Query query = em.createQuery("from BaseModule fe where id = :Id"); query.setParameter("Id", id); return (BaseModule) query.getSingleResult(); }
From source file:com.grummages.app.rest.entity.service.ListingAddonRESTFacade.java
@GET @Path("count") @Produces("text/plain") @Transactional/* w w w . j ava2 s.c om*/ public String count() { try { Query query = entityManager.createQuery("SELECT count(o) FROM ListingAddon AS o"); return query.getSingleResult().toString(); } finally { entityManager.close(); } }
From source file:de.crowdcode.bitemporal.example.AddressRepository.java
public Address findById(Long id) { Query query = em.createQuery("select c from AddressImpl c where c.id = :id"); query.setParameter("id", id); return (Address) query.getSingleResult(); }
From source file:DAO.IMCDAOImpl.java
@Transactional @Override//from w w w. j ava 2s .c o m public IMCEntity find(int id) { Query q = em.createQuery("SELECT i FROM IMCEntity i where i.id = ?"); q.setParameter(1, id); try { return (IMCEntity) q.getSingleResult(); } catch (NoResultException e) { return null; } }
From source file:org.opentides.dao.impl.NotificationDaoImpl.java
@Override @Transactional(readOnly = true)/* ww w.j a va2s .c o m*/ public long countNewPopup(long userId) { String queryString = getJpqlQuery("jpql.notification.countNewPopup"); Query queryObject = getEntityManager().createQuery(queryString); queryObject.setParameter("userId", userId); return (Long) queryObject.getSingleResult(); }
From source file:com.grummages.app.rest.entity.service.ListingPaymentRESTFacade.java
@GET @Path("count") @Produces("text/plain") @Transactional/*from w w w . java 2 s . c o m*/ public String count() { try { Query query = entityManager.createQuery("SELECT count(o) FROM ListingPayment AS o"); return query.getSingleResult().toString(); } finally { entityManager.close(); } }
From source file:org.simbasecurity.core.config.store.DatabaseConfigurationStore.java
public String getValue(ConfigurationParameter parameter) { Query query = entityManager.createNativeQuery(SQL_GET); query.setParameter(1, String.valueOf(parameter)); try {/* ww w . ja va 2s.co m*/ return (String) query.getSingleResult(); } catch (Exception ignore) { return ""; } }
From source file:de.berlios.jhelpdesk.dao.jpa.TicketDAOJpa.java
public Long countTicketsWithFilter(final TicketFilter ticketFilter) throws DAOException { return (Long) this.jpaTemplate.execute(new JpaCallback() { public Object doInJpa(EntityManager em) throws PersistenceException { Query q = new QueryBuilder(ticketFilter, em).getFilteredQuery(true); return q.getSingleResult(); }/*from ww w.j a va 2 s. co m*/ }); }
From source file:org.fornax.cartridges.sculptor.framework.test.AbstractAppEngineJpaTests.java
/** * Counts the number of stored instances of an object. *///from w w w. j a v a 2s .com protected int countRowsInTable(Class<?> domainObjectClass) throws Exception { Query query = getEntityManager() .createQuery("select count(e) from " + domainObjectClass.getSimpleName() + " e"); return (Integer) query.getSingleResult(); }
From source file:com.pet.demo.repository.jpa.JpaAccountRepositoryImpl.java
public Account findById(int id) { // using 'join fetch' because a single query should load both owners and pets // using 'left join fetch' because it might happen that an owner does not have pets yet Query query = this.em.createQuery("SELECT account FROM Account account WHERE account.id =:id"); query.setParameter("id", id); return (Account) query.getSingleResult(); }