use of javax.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 javax.persistence.NamedQuery in project BroadleafCommerce by BroadleafCommerce.
the class MergePersistenceUnitManager method addNamedQueriesToPersistenceUnits.
protected boolean addNamedQueriesToPersistenceUnits(boolean weaverRegistered) throws Exception {
// still be transformed by the previous registered transformers
for (PersistenceUnitInfo pui : mergedPus.values()) {
// Add annotated named query support from QueryConfiguration beans
List<NamedQuery> namedQueries = new ArrayList<>();
List<NamedNativeQuery> nativeQueries = new ArrayList<>();
for (QueryConfiguration config : queryConfigurations) {
if (pui.getPersistenceUnitName().equals(config.getPersistenceUnit())) {
NamedQueries annotation = config.getClass().getAnnotation(NamedQueries.class);
if (annotation != null) {
namedQueries.addAll(Arrays.asList(annotation.value()));
}
NamedNativeQueries annotation2 = config.getClass().getAnnotation(NamedNativeQueries.class);
if (annotation2 != null) {
nativeQueries.addAll(Arrays.asList(annotation2.value()));
}
}
}
if (!namedQueries.isEmpty() || !nativeQueries.isEmpty()) {
QueryConfigurationClassTransformer transformer = new QueryConfigurationClassTransformer(namedQueries, nativeQueries, pui.getManagedClassNames());
try {
pui.addTransformer(transformer);
} catch (Exception e) {
weaverRegistered = handleClassTransformerRegistrationProblem(transformer, e);
}
}
}
return weaverRegistered;
}
use of javax.persistence.NamedQuery in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method addNamedQueryIfNeeded.
private void addNamedQueryIfNeeded(NamedQuery annotation, List<NamedQuery> queries) {
if (annotation != null) {
String queryName = annotation.name();
boolean present = false;
for (NamedQuery current : queries) {
if (current.name().equals(queryName)) {
present = true;
break;
}
}
if (!present) {
queries.add(annotation);
}
}
}
use of javax.persistence.NamedQuery in project hibernate-orm by hibernate.
the class NamedQueryTest method testNamedQueriesOrdinalParametersAreZeroBased.
@Test
public void testNamedQueriesOrdinalParametersAreZeroBased() {
doInHibernate(this::sessionFactory, session -> {
Query query = session.getNamedQuery("NamedQuery");
query.setParameter(0, GAME_TITLES[0]);
List list = query.getResultList();
assertEquals(1, list.size());
});
}
use of javax.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());
});
}
Aggregations