Package javax.persistence

Examples of javax.persistence.Query


     * Finds all callback events.
     * @return events
     */
    public List findAll(){
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        Query query = entityManager.createNamedQuery("findAll");
        return query.getResultList();
    }
View Full Code Here


     */
    @ExcludeDefaultInterceptors
    @ExcludeClassInterceptors
    public void deleteAll() {
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        Query query = entityManager.createNamedQuery("findAll");
        List lstEvent = query.getResultList();
        for (Object obj : lstEvent) {
            CallbackLogger callbackLogger = (CallbackLogger) obj;
            if (callbackLogger != null) {
                entityManager.remove(callbackLogger);
            }
View Full Code Here

    /**
     * Calls an EJB QL named query defined by annotation.
     */
    public void callNamedQuery() {
        Query query = entityManager.createNamedQuery("findByName");
        query.setParameter("entityName", ENTITY_NAME_ROOT + Integer.toString((MAX_ENTITIES - 1)));
        List simpleEntityResult = query.getResultList();
        assertEquals(simpleEntityResult.size(), 1, "The query did not return any value.");
        for (int i = 0; i < simpleEntityResult.size(); i++) {
            SimpleEntity simpleEntity = (SimpleEntity) simpleEntityResult.get(i);
            assertEquals(simpleEntity.getId(), MAX_ENTITIES - 1, "The bean was not correctly returned");
         }
View Full Code Here

    /**
     * Calls a native query defined by annotation.
     */
    public void callNamedNativeQuery() {
        Query query = entityManager.createNamedQuery("findByAll");
        List simpleEntityResult = query.getResultList();
        // verifies if all entities were correctly returned.
        checkQueryResult(simpleEntityResult);
    }
View Full Code Here

    /**
     * Uses the createQuery method of the EntityManager.
     */
    public void callCreateQuery() {
        Query query = entityManager.createQuery(EJBQL_QUERY);
        query.setParameter("entityname", ENTITY_NAME_ROOT + "%");
        List simpleEntityResult = query.getResultList();

        // verifies if all entities were correctly returned.
        checkQueryResult(simpleEntityResult);
    }
View Full Code Here

    /**
     * Calls the method createNative Query that has only the sqlQuery as
     * parameter.
     */
    public void callCreateNativeQuery00() {
        Query query = entityManager.createNativeQuery(NATIVE_QUERY);
        List simpleEntityResult = query.getResultList();

        // verifies if the list returned has the same number of entities that
        // was created
        assertEquals(MAX_ENTITIES, simpleEntityResult.size(), "The method did not returned all entities.");

View Full Code Here

    /**
     * Calls the method createNativeQuery that has the sqlQuery and the bean
     * class as parameters.
     */
    public void callCreateNativeQuery01() {
        Query query = entityManager.createNativeQuery(NATIVE_QUERY, SimpleEntity.class);
        List simpleEntityResult = query.getResultList();

        // verifies if all entities were correctly returned.
        checkQueryResult(simpleEntityResult);
    }
View Full Code Here

    /**
     * Calls the method that has the sqlQuery and the resultSetMapping as
     * parameters.
     */
    public void callCreateNativeQuery02() {
        Query query = entityManager.createNativeQuery(NATIVE_QUERY_2, "MappedSimpleEntity");
        query.setParameter(1, new Integer(0));

        List simpleEntityResult = query.getResultList();

        // verifies if all entities were correctly returned.
        checkQueryResult(simpleEntityResult);
    }
View Full Code Here

    /**
     * @return list of authors.
     */
    @SuppressWarnings("unchecked")
    public List<Author> listOfAuthors() {
        Query auteurs = entityManager.createNamedQuery("allAuthors");
        return auteurs.getResultList();
    }
View Full Code Here

      catch (SystemException e)
      {
         throw new RuntimeException(e);
      }
      if (tx != null) throw new RuntimeException("THERE IS A TRANSACTION!!!");
      Query q = manager.createQuery("SELECT c FROM Customer c");
      List l = q.getResultList();
      if (l.size() == 0) throw new RuntimeException("failed");
      org.hibernate.Query q2 = session.createQuery("FROM Customer c");
      l = q2.list();
      if (l.size() == 0) throw new RuntimeException("failed");
View Full Code Here

TOP

Related Classes of javax.persistence.Query

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.