use of javax.persistence.NamedNativeQuery in project hibernate-orm by hibernate.
the class NamedQueryTest method testNativeNamedQueriesOrdinalParametersAreZeroBased.
@Test
public void testNativeNamedQueriesOrdinalParametersAreZeroBased() {
doInHibernate(this::sessionFactory, session -> {
Query query = session.getNamedNativeQuery("NamedNativeQuery");
query.setParameter(0, GAME_TITLES[0]);
List list = query.getResultList();
assertEquals(1, list.size());
});
}
use of javax.persistence.NamedNativeQuery in project hibernate-orm by hibernate.
the class NamedQueryTest method testNativeNamedQueriesOrdinalParametersConflict2.
@Test
public void testNativeNamedQueriesOrdinalParametersConflict2() {
doInJPA(this::entityManagerFactory, entityManager -> {
Query query = entityManager.createNamedQuery("NamedNativeQuery");
query.setParameter(1, GAME_TITLES[0]);
List list = query.getResultList();
assertEquals(1, list.size());
final Session session = entityManager.unwrap(Session.class);
final org.hibernate.query.Query sessionQuery = session.getNamedNativeQuery("NamedNativeQuery");
sessionQuery.setParameter(0, GAME_TITLES[0]);
list = sessionQuery.getResultList();
query.setParameter(1, GAME_TITLES[0]);
assertEquals(1, list.size());
});
}
use of javax.persistence.NamedNativeQuery in project hibernate-orm by hibernate.
the class NamedQueryTest method testNativeNamedQueriesOrdinalParametersConflict.
@Test
public void testNativeNamedQueriesOrdinalParametersConflict() {
doInJPA(this::entityManagerFactory, entityManager -> {
Query query = entityManager.createNamedQuery("NamedNativeQuery");
query.setParameter(1, GAME_TITLES[0]);
List list = query.getResultList();
assertEquals(1, list.size());
final Session session = entityManager.unwrap(Session.class);
final org.hibernate.query.Query sessionQuery = session.createSQLQuery("select * from Game g where title = ?");
sessionQuery.setParameter(0, GAME_TITLES[0]);
list = sessionQuery.getResultList();
query.setParameter(1, GAME_TITLES[0]);
assertEquals(1, list.size());
});
}
use of javax.persistence.NamedNativeQuery in project hibernate-orm by hibernate.
the class NamedQueryTest method testNativeNamedQueriesOrdinalParametersAreOneBased.
@Test
public void testNativeNamedQueriesOrdinalParametersAreOneBased() {
doInJPA(this::entityManagerFactory, entityManager -> {
Query query = entityManager.createNamedQuery("NamedNativeQuery");
query.setParameter(1, GAME_TITLES[0]);
List list = query.getResultList();
assertEquals(1, list.size());
});
}
use of javax.persistence.NamedNativeQuery in project hibernate-orm by hibernate.
the class JPAMetadataProvider method getDefaults.
@Override
public Map<Object, Object> getDefaults() {
if (defaults == null) {
defaults = new HashMap<Object, Object>();
XMLContext.Default xmlDefaults = xmlContext.getDefault(null);
defaults.put("schema", xmlDefaults.getSchema());
defaults.put("catalog", xmlDefaults.getCatalog());
defaults.put("delimited-identifier", xmlDefaults.getDelimitedIdentifier());
List<Class> entityListeners = new ArrayList<Class>();
for (String className : xmlContext.getDefaultEntityListeners()) {
try {
entityListeners.add(classLoaderAccess.classForName(className));
} catch (ClassLoadingException e) {
throw new IllegalStateException("Default entity listener class not found: " + className);
}
}
defaults.put(EntityListeners.class, entityListeners);
for (Element element : xmlContext.getAllDocuments()) {
@SuppressWarnings("unchecked") List<Element> elements = element.elements("sequence-generator");
List<SequenceGenerator> sequenceGenerators = (List<SequenceGenerator>) defaults.get(SequenceGenerator.class);
if (sequenceGenerators == null) {
sequenceGenerators = new ArrayList<SequenceGenerator>();
defaults.put(SequenceGenerator.class, sequenceGenerators);
}
for (Element subelement : elements) {
sequenceGenerators.add(JPAOverriddenAnnotationReader.buildSequenceGeneratorAnnotation(subelement));
}
elements = element.elements("table-generator");
List<TableGenerator> tableGenerators = (List<TableGenerator>) defaults.get(TableGenerator.class);
if (tableGenerators == null) {
tableGenerators = new ArrayList<TableGenerator>();
defaults.put(TableGenerator.class, tableGenerators);
}
for (Element subelement : elements) {
tableGenerators.add(JPAOverriddenAnnotationReader.buildTableGeneratorAnnotation(subelement, xmlDefaults));
}
List<NamedQuery> namedQueries = (List<NamedQuery>) defaults.get(NamedQuery.class);
if (namedQueries == null) {
namedQueries = new ArrayList<NamedQuery>();
defaults.put(NamedQuery.class, namedQueries);
}
List<NamedQuery> currentNamedQueries = JPAOverriddenAnnotationReader.buildNamedQueries(element, false, xmlDefaults, classLoaderAccess);
namedQueries.addAll(currentNamedQueries);
List<NamedNativeQuery> namedNativeQueries = (List<NamedNativeQuery>) defaults.get(NamedNativeQuery.class);
if (namedNativeQueries == null) {
namedNativeQueries = new ArrayList<NamedNativeQuery>();
defaults.put(NamedNativeQuery.class, namedNativeQueries);
}
List<NamedNativeQuery> currentNamedNativeQueries = JPAOverriddenAnnotationReader.buildNamedQueries(element, true, xmlDefaults, classLoaderAccess);
namedNativeQueries.addAll(currentNamedNativeQueries);
List<SqlResultSetMapping> sqlResultSetMappings = (List<SqlResultSetMapping>) defaults.get(SqlResultSetMapping.class);
if (sqlResultSetMappings == null) {
sqlResultSetMappings = new ArrayList<SqlResultSetMapping>();
defaults.put(SqlResultSetMapping.class, sqlResultSetMappings);
}
List<SqlResultSetMapping> currentSqlResultSetMappings = JPAOverriddenAnnotationReader.buildSqlResultsetMappings(element, xmlDefaults, classLoaderAccess);
sqlResultSetMappings.addAll(currentSqlResultSetMappings);
List<NamedStoredProcedureQuery> namedStoredProcedureQueries = (List<NamedStoredProcedureQuery>) defaults.get(NamedStoredProcedureQuery.class);
if (namedStoredProcedureQueries == null) {
namedStoredProcedureQueries = new ArrayList<NamedStoredProcedureQuery>();
defaults.put(NamedStoredProcedureQuery.class, namedStoredProcedureQueries);
}
List<NamedStoredProcedureQuery> currentNamedStoredProcedureQueries = JPAOverriddenAnnotationReader.buildNamedStoreProcedureQueries(element, xmlDefaults, classLoaderAccess);
namedStoredProcedureQueries.addAll(currentNamedStoredProcedureQueries);
}
}
return defaults;
}
Aggregations