Package javax.persistence

Examples of javax.persistence.EntityManager.createNativeQuery()


        TypedQuery<Order> tq = em.createQuery(criteriaQuery);
        tq.setParameter("maxDate", maxDate);
        List<Order> criteriaResults = tq.getResultList();
        assertEquals(N_ORDERS / 2, criteriaResults.size());

        Query nativeQuery = em.createNativeQuery("Select * from CRIT_RES_ORD o WHERE (o.cdate < ?1)", Order.class);
        nativeQuery.setParameter(1, maxDate);
        List<Order> nativeResults = nativeQuery.getResultList();
        assertEquals(N_ORDERS / 2, nativeResults.size());

        for (Order o : jpqlResults) {
View Full Code Here


    public void findEntityA_Coll_StringXml() {
        EntityManager em = emf.createEntityManager();
        EntityA_Coll_StringXml a = em.find(EntityA_Coll_StringXml.class, ID);
        checkEntityA_Coll_StringXml(a);
       
        Query q = em.createNativeQuery("select count(*) from EntityA_Coll_StringXml_nickNames");
        Object obj = q.getSingleResult();
        // ensure that multiple rows are inserted into the table (the column is not serialized)
        assertEquals(numBasicTypes, obj);         
       
       
View Full Code Here

            for (ClassMapping mapping : ((ClassMapping[]) emf
                .getConfiguration().getMetaDataRepositoryInstance()
                .getMetaDatas())) {
                Query q =
                    em.createNativeQuery("DROP TABLE "
                        + mapping.getTable().getName());
                q.executeUpdate();
            }
            em.getTransaction().commit();
            em.close();
View Full Code Here

    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    Long entCount = (Long) em.createQuery(
        "select count(s) from DefaultValueComponentTestEntity s where s.id = "
            + expectedId.toString()).getSingleResult();
    BigInteger auditCount = (BigInteger) em.createNativeQuery(
        "select count(ID) from DefaultValueComponentTestEntity_AUD s where s.id = "
            + expectedId.toString()).getSingleResult();
    String comp2Str1Rev1 = (String) em
        .createNativeQuery(
            "select COMP2_STR1 from DefaultValueComponentTestEntity_AUD s where rev=1 and s.id = "
View Full Code Here

        "select count(s) from DefaultValueComponentTestEntity s where s.id = "
            + expectedId.toString()).getSingleResult();
    BigInteger auditCount = (BigInteger) em.createNativeQuery(
        "select count(ID) from DefaultValueComponentTestEntity_AUD s where s.id = "
            + expectedId.toString()).getSingleResult();
    String comp2Str1Rev1 = (String) em
        .createNativeQuery(
            "select COMP2_STR1 from DefaultValueComponentTestEntity_AUD s where rev=1 and s.id = "
                + expectedId.toString()).getSingleResult();
    String comp2Str1Rev2 = (String) em
        .createNativeQuery(
View Full Code Here

            + expectedId.toString()).getSingleResult();
    String comp2Str1Rev1 = (String) em
        .createNativeQuery(
            "select COMP2_STR1 from DefaultValueComponentTestEntity_AUD s where rev=1 and s.id = "
                + expectedId.toString()).getSingleResult();
    String comp2Str1Rev2 = (String) em
        .createNativeQuery(
            "select COMP2_STR1 from DefaultValueComponentTestEntity_AUD s where rev=2 and s.id = "
                + expectedId.toString()).getSingleResult();
    assert Long.valueOf(1L).equals(entCount);
    assert BigInteger.valueOf(2L).equals(auditCount);
View Full Code Here

    }

    @Test
    public void shouldRespectWriteExpression() {
        EntityManager em = getEntityManager();
        List resultList = em.createNativeQuery("select size_in_cm from t_staff_AUD where id ="+id).getResultList();
        assert 1 == resultList.size();
        Double sizeInCm = (Double) resultList.get(0);
        assert sizeInCm.equals(HEIGHT_CENTIMETERS);
    }
View Full Code Here

    em.persist( item );
    assertTrue( em.contains( item ) );
    em.getTransaction().commit();

    em.getTransaction().begin();
    item = (Item) em.createNativeQuery( "select * from Item", Item.class ).getSingleResult();
    assertNotNull( item );
    assertEquals( "Micro$oft mouse", item.getDescr() );
    em.remove( item );
    em.getTransaction().commit();

View Full Code Here

    em.persist( item );
    assertTrue( em.contains( item ) );
    em.getTransaction().commit();

    em.getTransaction().begin();
    item = (Item) em.createNativeQuery( "select name as itemname, descr as itemdescription from Item", "getItem" )
        .getSingleResult();
    assertNotNull( item );
    assertEquals( "Micro$oft mouse", item.getDescr() );
    em.remove( item );
    em.getTransaction().commit();
View Full Code Here

    w.setModel( "Minimic" );
    w.setSerial( "0100202002" );
    em.persist( w );
    em.getTransaction().commit();
    em.getTransaction().begin();
    Query query = em.createNativeQuery( "select * from Wallet w where w.brand = ?", Wallet.class );
    query.setParameter( 1, "Lacoste" );
    w = (Wallet) query.getSingleResult();
    assertNotNull( w );
    em.remove( w );
    em.getTransaction().commit();
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.