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);
}
}
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();
}
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);
}
}
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();
}
}
Aggregations