use of jakarta.persistence.NamedQuery in project hibernate-orm by hibernate.
the class NamedQueryTest method testNamedQueryOrdinalParametersConflict.
@Test
public void testNamedQueryOrdinalParametersConflict() {
doInJPA(this::entityManagerFactory, entityManager -> {
Query query = entityManager.createNamedQuery("NamedQuery");
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.createQuery("select g from Game g where title = ?1");
sessionQuery.setParameter(1, GAME_TITLES[0]);
list = sessionQuery.getResultList();
query.setParameter(1, GAME_TITLES[0]);
assertEquals(1, list.size());
});
}
use of jakarta.persistence.NamedQuery in project hibernate-orm by hibernate.
the class NamedQueryTest method testNamedQueriesOrdinalParametersAreOneBased.
@Test
public void testNamedQueriesOrdinalParametersAreOneBased() {
doInJPA(this::entityManagerFactory, entityManager -> {
Query query = entityManager.createNamedQuery("NamedQuery");
query.setParameter(1, GAME_TITLES[0]);
List list = query.getResultList();
assertEquals(1, list.size());
});
}
use of jakarta.persistence.NamedQuery in project hibernate-orm by hibernate.
the class NamedQueryTest method testNamedQueryOrdinalParametersConflict2.
@Test
public void testNamedQueryOrdinalParametersConflict2() {
doInJPA(this::entityManagerFactory, entityManager -> {
Query query = entityManager.createNamedQuery("NamedQuery");
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.getNamedQuery("NamedQuery");
sessionQuery.setParameter(1, GAME_TITLES[0]);
list = sessionQuery.getResultList();
query.setParameter(1, GAME_TITLES[0]);
assertEquals(1, list.size());
});
}
use of jakarta.persistence.NamedQuery in project eclipselink by eclipse-ee4j.
the class JavaEntity method buildQueries.
protected Map<String, IQuery> buildQueries() {
Map<String, IQuery> queries = new HashMap<>();
try {
Class<?> type = getType().getType();
Annotation[] annotations = type.getAnnotations();
NamedQueries namedQueries = getAnnotation(annotations, NamedQueries.class);
if (namedQueries != null) {
for (NamedQuery namedQuery : namedQueries.value()) {
IQuery query = buildQuery(namedQuery);
queries.put(namedQuery.name(), query);
}
} else {
NamedQuery namedQuery = getAnnotation(annotations, NamedQuery.class);
if (namedQuery != null) {
IQuery query = buildQuery(namedQuery);
queries.put(namedQuery.name(), query);
}
}
} catch (Exception e) {
// Ignore
}
return queries;
}
Aggregations