Package javax.persistence

Examples of javax.persistence.EntityManager.createNativeQuery()


    begin();
    EntityManager em = createEntityManager();

    String nativeQuery = "{ $and: [ { name : 'Portia' }, { author : 'Oscar Wilde' } ] }";
    try {
      em.createNativeQuery( nativeQuery ).getSingleResult();
      commit();
    }
    catch (Exception he) {
      rollback();
      String message = he.getMessage();
View Full Code Here


  public void testListMultipleResultQuery() throws Exception {
    begin();
    EntityManager em = createEntityManager();
    String nativeQuery = "{ $query : { author : 'Oscar Wilde' }, $orderby : { name : 1 } }";
    @SuppressWarnings("unchecked")
    List<OscarWildePoem> results = em.createNativeQuery( nativeQuery, OscarWildePoem.class ).getResultList();

    assertThat( results ).as( "Unexpected number of results" ).hasSize( 2 );
    assertAreEquals( athanasia, results.get( 0 ) );
    assertAreEquals( portia, results.get( 1 ) );
View Full Code Here

  public void testEntitiesInsertedInCurrentSessionAreFoundByNativeQuery() throws Exception {
    begin();
    EntityManager em = createEntityManager();

    String nativeQuery = "{ name : 'Her Voice' }";
    Query query = em.createNativeQuery( nativeQuery, OscarWildePoem.class );

    List<OscarWildePoem> results = query.getResultList();
    assertThat( results ).as( "Unexpected number of results" ).hasSize( 0 );

    OscarWildePoem voice = new OscarWildePoem( 3L, "Her Voice", "Oscar Wilde" );
View Full Code Here

  public void testSingleResultQueryUsingExtendedSyntax() throws Exception {
    begin();
    EntityManager em = createEntityManager();
    String nativeQuery = "db.WILDE_POEM.find({ '$query' : { 'name' : 'Athanasia' }, '$orderby' : { 'name' : 1 } })";
    @SuppressWarnings("unchecked")
    List<OscarWildePoem> results = em.createNativeQuery( nativeQuery, OscarWildePoem.class ).getResultList();

    assertThat( results ).as( "Unexpected number of results" ).hasSize( 1 );
    assertAreEquals( athanasia, results.get( 0 ) );

    commit();
View Full Code Here

  public Query createNativeQuery(String arg0)
  {
    EntityManager em = getPersistenceContext(false);
    try {
      return em.createNativeQuery(arg0);
    } finally {
      if(em == detachedManager)
        em.clear();
    }
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  public Query createNativeQuery(String arg0, Class arg1)
  {
    EntityManager em = getPersistenceContext(false);
    try {
      return em.createNativeQuery(arg0, arg1);
    } finally {
      if(em == detachedManager)
        em.clear();
    }
  }
View Full Code Here

  public Query createNativeQuery(String arg0, String arg1)
  {
    EntityManager em = getPersistenceContext(false);
    try {
      return em.createNativeQuery(arg0, arg1);
    } finally {
      if(em == detachedManager)
        em.clear();
    }
  }
View Full Code Here

        // get the data from the database. Version should always have been
        // updated in this case.
        em = getEntityManagerFactory().createEntityManager();
        em.setProperty(RETRIEVE_MODE_PROP, CacheRetrieveMode.BYPASS);
        CacheableEntity ceFromDB =
            (CacheableEntity) em.createNativeQuery("Select * from CacheableEntity where ID = 1", CacheableEntity.class)
                .getSingleResult();

        XmlCacheableEntity xceFromDB =
            (XmlCacheableEntity) em.createNativeQuery("Select * from XmlCacheableEntity where ID = 1",
                XmlCacheableEntity.class).getSingleResult();
View Full Code Here

        CacheableEntity ceFromDB =
            (CacheableEntity) em.createNativeQuery("Select * from CacheableEntity where ID = 1", CacheableEntity.class)
                .getSingleResult();

        XmlCacheableEntity xceFromDB =
            (XmlCacheableEntity) em.createNativeQuery("Select * from XmlCacheableEntity where ID = 1",
                XmlCacheableEntity.class).getSingleResult();

        assertEquals(version + 1, ceFromDB.getVersion());
        assertEquals(version + 1, xceFromDB.getVersion());
        em.close();
View Full Code Here

    // (it forces us to use enums not strings, which were deleted)
    executeInTransaction(new Runnable() {
      @Override
      public void run() {
        EntityManager em = getEntityManagerProvider().get();
        Query nativeQuery = em.createNativeQuery("UPDATE hostcomponentstate SET current_state=?1 WHERE current_state in (?2, ?3)");
        nativeQuery.setParameter(1, "INSTALLED");
        nativeQuery.setParameter(2, "STOP_FAILED");
        nativeQuery.setParameter(3, "START_FAILED");
        nativeQuery.executeUpdate();
      }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.