List of usage examples for javax.persistence Query setParameter
Query setParameter(int position, Object value);
From source file:com.sct.descubriendoturuta.service.UsuarioServiceImpl.java
@Override @Transactional//from www . j a v a 2s .co m public List<Invitacion> obtenerUsuariosInvitados(int rutaId) { Query query = em.createQuery("select i from Invitacion i WHERE i.ruta.id = :p"); query.setParameter("p", rutaId); return query.getResultList(); }
From source file:de.berlios.jhelpdesk.dao.jpa.TicketFilterDAOJpa.java
@Transactional(readOnly = false) public void saveOrUpdate(final TicketFilter filter) { if (filter.getId() == null) { this.jpaTemplate.persist(filter); } else {/*ww w. ja v a2 s . co m*/ this.jpaTemplate.execute(new JpaCallback<TicketFilter>() { public TicketFilter doInJpa(EntityManager em) throws PersistenceException { TicketFilterDAOJpa.this.deleteFilterItems(em, filter.getId()); em.merge(filter); // WORKAROUND: Jest jaki problem z zapisaniem do bazy pl z dat // ustawionych na null, jeli wczeniej miay jak warto... (OpenJPA 1.2.2) Query updateQuery = em .createNativeQuery("UPDATE ticket_filters SET begin_date=?1, end_date=?2 WHERE id=?3"); updateQuery.setParameter(1, filter.getBeginDate()); updateQuery.setParameter(2, filter.getEndDate()); updateQuery.setParameter(3, filter.getId()); updateQuery.executeUpdate(); return null; } }); } }
From source file:org.simbasecurity.core.domain.repository.PolicyDatabaseRepository.java
@SuppressWarnings("unchecked") @Override/*from ww w . j a v a 2 s. c om*/ public Collection<Policy> find(User user) { Query query = entityManager.createQuery("SELECT DISTINCT policy " + "FROM PolicyEntity policy " + "JOIN policy.roles role JOIN role.users user " + "WHERE user=:user"); query.setParameter("user", user); return query.getResultList(); }
From source file:com.impetus.kwitter.service.TwitterService.java
@Override public List<User> findPersonalDetailByName(String name) { Query q = em.createQuery("select u.personalDetail.name from User u where u.personalDetail.name =:name"); q.setParameter("name", name); List<User> users = q.getResultList(); return users; }
From source file:com.june.app.board.repository.jpa.BoardRepositoryImpl.java
@Override public Board boardGet(long seq) { Query query = this.em .createQuery("SELECT board FROM Board board WHERE board.useYn ='Y' and board.nttId =:nttId"); query.setParameter("nttId", seq); return (Board) query.getSingleResult(); }
From source file:gwap.rest.UserPicture.java
protected List<ArtResource> getRandomPictures(String count, String deviceId, String origin) { Query query = entityManager.createNamedQuery("artResource.getRandomPictures"); query.setParameter("deviceId", deviceId); query.setParameter("origin", origin); query.setMaxResults(Integer.parseInt(count)); List<ArtResource> artResources = query.getResultList(); return artResources; }
From source file:es.ucm.fdi.dalgs.module.repository.ModuleRepository.java
public Module existByCode(String code, Long id_degree) { Degree d = em.getReference(Degree.class, id_degree); Query query = em.createQuery("select m from Module m where m.info.code=?1 and m.degree = ?2"); query.setParameter(1, code); query.setParameter(2, d);/*from w ww . j a va 2 s. c o m*/ if (query.getResultList().isEmpty()) return null; else return (Module) query.getSingleResult(); }
From source file:org.messic.server.datamodel.jpaimpl.DAOJPAUser.java
/** * Get User by username, null if not found * /*from w w w . ja v a 2s. c o m*/ * @param username {@link String} username to find * @return {@link MDOUser} user found, null if not found */ @Override @Transactional public MDOUser getUserByLogin(String username) { Query query = entityManager.createQuery("from MDOUser as p where p.login = :login"); query.setParameter("login", username); @SuppressWarnings("unchecked") List<MDOUser> results = query.getResultList(); if (results == null || results.size() <= 0) { return null; } else { return results.get(0); } }
From source file:com.telefonica.euro_iaas.paasmanager.dao.impl.NetworkDaoJpaImpl.java
private Network findNetworkWithSubNet(String name, String vdc, String region) throws EntityNotFoundException { Query query = getEntityManager().createQuery("select p from Network p left join " + " fetch p.subNets where p.name = :name and p.vdc = :vdc and p.region =:region"); query.setParameter("name", name); query.setParameter("region", region); if (vdc == null) { query.setParameter("vdc", ""); } else {/*from ww w. j ava 2s.co m*/ query.setParameter("vdc", vdc); } Network network = null; try { network = (Network) query.getSingleResult(); } catch (NoResultException e) { String message = " No network found in the database with id: " + name + " and vdc " + vdc + " region " + region + " Exception: " + e.getMessage(); throw new EntityNotFoundException(Network.class, "name", name); } return network; }
From source file:com.telefonica.euro_iaas.paasmanager.dao.impl.ProductReleaseDaoJpaImpl.java
public ProductRelease loadProductReleaseWithMetadata(String name) throws EntityNotFoundException { Query query = getEntityManager().createQuery( "select p from ProductRelease p left join " + " fetch p.metadatas where p.name = :name"); query.setParameter("name", name); ProductRelease productRelease = null; try {// ww w. ja v a 2 s.co m productRelease = (ProductRelease) query.getResultList().get(0); } catch (Exception e) { String message = " No ProductRelease found in the database with id: " + name + " Exception: " + e.getMessage(); throw new EntityNotFoundException(ProductRelease.class, "name", name); } return productRelease; }