Examples of createNativeQuery()


Examples of javax.persistence.EntityManager.createNativeQuery()

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

    String nativeQuery = "MATCH ( n:" + TABLE_NAME + " { name:'Portia', author:'Oscar Wilde' } ) RETURN n";
    OscarWildePoem poem = (OscarWildePoem) em.createNativeQuery( nativeQuery, OscarWildePoem.class ).getSingleResult();

    assertAreEquals( portia, poem );

    commit();
    close( em );
View Full Code Here

Examples of javax.persistence.EntityManager.createNativeQuery()

  public void testListMultipleResultQuery() throws Exception {
    begin();
    EntityManager em = createEntityManager();
    String nativeQuery = "MATCH ( n:" + TABLE_NAME + " { author:'Oscar Wilde' } ) RETURN n ORDER BY n.name";
    @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

Examples of javax.persistence.EntityManager.createNativeQuery()

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

    String nativeQuery = "MATCH ( n:" + TABLE_NAME + " { name:{name}, author:'Oscar Wilde' } ) RETURN n";
    Query query = em.createNativeQuery( nativeQuery, OscarWildePoem.class );
    query.setParameter( "name", "Portia" );
    OscarWildePoem poem = (OscarWildePoem) query.getSingleResult();

    assertAreEquals( portia, poem );
View Full Code Here

Examples of javax.persistence.EntityManager.createNativeQuery()

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

    String nativeQuery = "MATCH ( n:" + TABLE_NAME + " { dateOfCreation:{creationDate}, author:'Oscar Wilde' } ) RETURN n";
    Query query = em.createNativeQuery( nativeQuery, OscarWildePoem.class );
    query.setParameter( "creationDate", new GregorianCalendar( 1810, 3, 10 ).getTime() );
    OscarWildePoem poem = (OscarWildePoem) query.getSingleResult();

    assertAreEquals( athanasia, poem );
View Full Code Here

Examples of javax.persistence.EntityManager.createNativeQuery()

  private Long executeQuery(String queryString) throws Exception {
    getTransactionManager().begin();
    final EntityManager em = getFactory().createEntityManager();
    @SuppressWarnings("unchecked")
    List<Object> results = em.createNativeQuery( queryString ).getResultList();
    Long uniqueResult = null;
    if ( !results.isEmpty() ) {
      uniqueResult = (Long) results.get( 0 );
    }
    commitOrRollback( true );
View Full Code Here

Examples of javax.persistence.EntityManager.createNativeQuery()

        try {
            String queryStr =
                    "SELECT id AS idparent, longVal AS idchild, CAST(NULL AS CHAR)  as missing FROM EGENERIC";
                    //"SELECT 1 as idparent, 2 as idchild,CAST(NULL AS CHAR) as missing "
                    // FROM sysibm.sysdummy1";
            Query q1 = em.createNativeQuery(queryStr, EParent.class);
           
            List resultList = q1.getResultList();
            assertNotNull(resultList);
           
            List <EParent> pList = new ArrayList<EParent>();
View Full Code Here

Examples of javax.persistence.EntityManager.createNativeQuery()

    public void testPartialEmbeddableLoadByJPQLQuery() {
        EntityManager em = emf.createEntityManager();
       
        try {
            String queryStr = "SELECT id AS idparent, longVal AS idchild FROM EGENERIC";
            Query q1 = em.createNativeQuery(queryStr, EParent.class);
           
            List resultList = q1.getResultList();
            assertNotNull(resultList);
           
            List <EParent> pList = new ArrayList<EParent>();
View Full Code Here

Examples of javax.persistence.EntityManager.createNativeQuery()

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

    String nativeQuery = "{ $and: [ { name : 'Portia' }, { author : 'Oscar Wilde' } ] }";
    OscarWildePoem poem = (OscarWildePoem) em.createNativeQuery( nativeQuery, OscarWildePoem.class ).getSingleResult();

    assertAreEquals( portia, poem );

    commit();
    close( em );
View Full Code Here

Examples of javax.persistence.EntityManager.createNativeQuery()

    String nativeQuery = "db.WILDE_POEM.find( "
        + "{ '$and' : [ { 'name' : 'Portia' }, { 'author' : 'Oscar Wilde' } ] }, "
        + "{ 'name' : 1 }"
        + " )";
    String result = (String) em.createNativeQuery( nativeQuery, "poemNameMapping" ).getSingleResult();

    assertThat( result ).isEqualTo( "Portia" );

    commit();
    close( em );
View Full Code Here

Examples of javax.persistence.EntityManager.createNativeQuery()

    String nativeQuery = "db.WILDE_POEM.find( "
        + "{ '$and' : [ { 'name' : 'Portia' }, { 'author' : 'Oscar Wilde' } ] }, "
        + "{ 'name' : 1, 'author' : 1 }"
        + " )";
    Object[] result = (Object[]) em.createNativeQuery( nativeQuery, "poemNameAuthorIdMapping" ).getSingleResult();

    assertThat( Arrays.asList( result ) ).containsExactly( "Portia", "Oscar Wilde", 1L );

    commit();
    close( em );
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.