use of jakarta.persistence.NamedNativeQuery in project hibernate-orm by hibernate.
the class JPAXMLOverriddenAnnotationReader method addNamedNativeQueryIfNeeded.
private void addNamedNativeQueryIfNeeded(NamedNativeQuery annotation, List<NamedNativeQuery> queries) {
if (annotation != null) {
String queryName = annotation.name();
boolean present = false;
for (NamedNativeQuery current : queries) {
if (current.name().equals(queryName)) {
present = true;
break;
}
}
if (!present) {
queries.add(annotation);
}
}
}
use of jakarta.persistence.NamedNativeQuery in project hibernate-orm by hibernate.
the class JPAXMLOverriddenAnnotationReader method getNamedNativeQueries.
private NamedNativeQueries getNamedNativeQueries(ManagedType root, XMLContext.Default defaults) {
List<NamedNativeQuery> queries = root instanceof JaxbEntity ? buildNamedNativeQueries(((JaxbEntity) root).getNamedNativeQuery(), defaults, classLoaderAccess) : new ArrayList<>();
if (defaults.canUseJavaAnnotations()) {
NamedNativeQuery annotation = getPhysicalAnnotation(NamedNativeQuery.class);
addNamedNativeQueryIfNeeded(annotation, queries);
NamedNativeQueries annotations = getPhysicalAnnotation(NamedNativeQueries.class);
if (annotations != null) {
for (NamedNativeQuery current : annotations.value()) {
addNamedNativeQueryIfNeeded(current, queries);
}
}
}
if (queries.size() > 0) {
AnnotationDescriptor ad = new AnnotationDescriptor(NamedNativeQueries.class);
ad.setValue("value", queries.toArray(new NamedNativeQuery[queries.size()]));
return AnnotationFactory.create(ad);
} else {
return null;
}
}
use of jakarta.persistence.NamedNativeQuery in project hibernate-orm by hibernate.
the class NamedQueryTest method testNativeNamedQueriesOrdinalParametersAreOneBased.
@Test
public void testNativeNamedQueriesOrdinalParametersAreOneBased(SessionFactoryScope scope) {
scope.inTransaction(session -> {
Query query = session.getNamedNativeQuery("NamedNativeQuery");
query.setParameter(1, GAME_TITLES[0]);
List list = query.getResultList();
assertEquals(1, list.size());
});
}
use of jakarta.persistence.NamedNativeQuery in project hibernate-orm by hibernate.
the class NamedQueryTest method testQueryHintLockMode.
@Test
@TestForIssue(jiraKey = "HHH-14816")
public void testQueryHintLockMode() {
doInJPA(this::entityManagerFactory, entityManager -> {
Query query = entityManager.createNamedQuery("NamedNativeQuery");
query.setHint(HINT_NATIVE_LOCK_MODE, "none");
query.setParameter(1, GAME_TITLES[0]);
assertEquals(LockMode.NONE, query.getHints().get(HINT_NATIVE_LOCK_MODE));
});
}
use of jakarta.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());
});
}
Aggregations