Search in sources :

Example 1 with NativeQueryImplementor

use of org.hibernate.query.spi.NativeQueryImplementor in project hibernate-orm by hibernate.

the class AbstractSharedSessionContract method createNativeQuery.

@Override
public NativeQueryImplementor createNativeQuery(String sqlString, String resultSetMapping) {
    checkOpen();
    checkTransactionSynchStatus();
    delayedAfterCompletion();
    try {
        NativeQueryImplementor query = createNativeQuery(sqlString);
        query.setResultSetMapping(resultSetMapping);
        return query;
    } catch (RuntimeException he) {
        throw exceptionConverter.convert(he);
    }
}
Also used : NativeQueryImplementor(org.hibernate.query.spi.NativeQueryImplementor)

Example 2 with NativeQueryImplementor

use of org.hibernate.query.spi.NativeQueryImplementor in project hibernate-orm by hibernate.

the class NamedQueryCollectionInitializer method initialize.

public void initialize(Serializable key, SharedSessionContractImplementor session) throws HibernateException {
    LOG.debugf("Initializing collection: %s using named query: %s", persister.getRole(), queryName);
    NativeQueryImplementor nativeQuery = session.getNamedNativeQuery(queryName);
    if (nativeQuery.getParameterMetadata().hasNamedParameters()) {
        nativeQuery.setParameter(nativeQuery.getParameterMetadata().getNamedParameterNames().iterator().next(), key, persister.getKeyType());
    } else {
        nativeQuery.setParameter(1, key, persister.getKeyType());
    }
    nativeQuery.setCollectionKey(key).setFlushMode(FlushMode.MANUAL).list();
}
Also used : NativeQueryImplementor(org.hibernate.query.spi.NativeQueryImplementor)

Example 3 with NativeQueryImplementor

use of org.hibernate.query.spi.NativeQueryImplementor in project hibernate-orm by hibernate.

the class AbstractSharedSessionContract method createNativeQuery.

@Override
public NativeQueryImplementor createNativeQuery(String sqlString, Class resultClass) {
    checkOpen();
    checkTransactionSynchStatus();
    delayedAfterCompletion();
    try {
        NativeQueryImplementor query = createNativeQuery(sqlString);
        handleNativeQueryResult(query, resultClass);
        return query;
    } catch (RuntimeException he) {
        throw exceptionConverter.convert(he);
    }
}
Also used : NativeQueryImplementor(org.hibernate.query.spi.NativeQueryImplementor)

Example 4 with NativeQueryImplementor

use of org.hibernate.query.spi.NativeQueryImplementor in project hibernate-orm by hibernate.

the class NativeQueryOrdinalParametersTest method testConflictWithSessionNativeQuery.

@Test
@TestForIssue(jiraKey = "HHH-11121")
public void testConflictWithSessionNativeQuery() {
    EntityManager em = getOrCreateEntityManager();
    final String sqlString = "SELECT * FROM GAME g WHERE title = ?";
    try {
        NativeQuery sqlQuery = em.unwrap(Session.class).createSQLQuery(sqlString);
        sqlQuery.setString(1, "Super Mario Brothers").setCacheable(true);
        List results = sqlQuery.list();
        assertEquals(1, results.size());
        NativeQueryImplementor query = (NativeQueryImplementor) em.createNativeQuery(sqlString);
        query.setString(1, "Super Mario Brothers");
        List list = query.list();
        assertEquals(1, list.size());
        sqlQuery = em.unwrap(Session.class).createSQLQuery(sqlString);
        sqlQuery.setString(1, "Super Mario Brothers").setCacheable(true);
        results = sqlQuery.list();
        assertEquals(1, results.size());
        query.setString(1, "Super Mario Brothers");
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) NativeQueryImplementor(org.hibernate.query.spi.NativeQueryImplementor) NativeQuery(org.hibernate.query.NativeQuery) List(java.util.List) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

NativeQueryImplementor (org.hibernate.query.spi.NativeQueryImplementor)4 List (java.util.List)1 EntityManager (javax.persistence.EntityManager)1 Session (org.hibernate.Session)1 NativeQuery (org.hibernate.query.NativeQuery)1 TestForIssue (org.hibernate.testing.TestForIssue)1 Test (org.junit.Test)1