use of org.hibernate.query.UnknownNamedQueryException in project hibernate-orm by hibernate.
the class AbstractSharedSessionContract method createNamedSelectionQuery.
@Override
public <R> SelectionQuery<R> createNamedSelectionQuery(String queryName, Class<R> expectedResultType) {
checkOpen();
pulseTransactionCoordinator();
delayedAfterCompletion();
// this method can be called for either a named HQL query or a named native query
// first see if it is a named HQL query
final NamedSqmQueryMemento namedHqlDescriptor = getFactory().getQueryEngine().getNamedObjectRepository().getSqmQueryMemento(queryName);
if (namedHqlDescriptor != null) {
return createNamedSqmSelectionQuery(namedHqlDescriptor, expectedResultType);
}
// otherwise, see if it is a named native query
final NamedNativeQueryMemento namedNativeDescriptor = getFactory().getQueryEngine().getNamedObjectRepository().getNativeQueryMemento(queryName);
if (namedNativeDescriptor != null) {
return createNamedNativeSelectionQuery(namedNativeDescriptor, expectedResultType);
}
throw new UnknownNamedQueryException(queryName);
}
use of org.hibernate.query.UnknownNamedQueryException in project hibernate-orm by hibernate.
the class AbstractSharedSessionContract method buildNamedQuery.
@SuppressWarnings("rawtypes")
protected QueryImplementor buildNamedQuery(String queryName, Function<NamedSqmQueryMemento, SqmQueryImplementor> namedSqmHandler, Function<NamedNativeQueryMemento, NativeQueryImplementor> namedNativeHandler) {
checkOpen();
pulseTransactionCoordinator();
delayedAfterCompletion();
// this method can be called for either a named HQL query or a named native query
// first see if it is a named HQL query
final NamedObjectRepository namedObjectRepository = getFactory().getQueryEngine().getNamedObjectRepository();
final NamedSqmQueryMemento namedSqmQueryMemento = namedObjectRepository.getSqmQueryMemento(queryName);
if (namedSqmQueryMemento != null) {
return namedSqmHandler.apply(namedSqmQueryMemento);
}
// otherwise, see if it is a named native query
final NamedNativeQueryMemento namedNativeDescriptor = namedObjectRepository.getNativeQueryMemento(queryName);
if (namedNativeDescriptor != null) {
return namedNativeHandler.apply(namedNativeDescriptor);
}
throw new UnknownNamedQueryException(queryName);
}
use of org.hibernate.query.UnknownNamedQueryException in project hibernate-orm by hibernate.
the class AbstractSharedSessionContract method buildNamedQuery.
@SuppressWarnings({ "rawtypes", "unchecked" })
protected <T> QueryImplementor<T> buildNamedQuery(String queryName, Class<T> resultType) {
try {
return buildNamedQuery(queryName, (memento) -> {
final SqmQueryImplementor query = memento.toQuery(this, resultType);
if (StringHelper.isEmpty(query.getComment())) {
query.setComment("dynamic query");
}
applyQuerySettingsAndHints(query);
if (memento.getLockOptions() != null) {
query.setLockOptions(memento.getLockOptions());
}
return query;
}, (memento) -> {
final NativeQueryImplementor query;
if (resultType == null) {
query = memento.toQuery(this);
} else {
query = memento.toQuery(this, resultType);
}
if (StringHelper.isEmpty(query.getComment())) {
query.setComment("dynamic native-SQL query");
}
applyQuerySettingsAndHints(query);
return query;
});
} catch (UnknownNamedQueryException e) {
// JPA expects this to mark the transaction for rollback only
transactionCoordinator.getTransactionDriverControl().markRollbackOnly();
// it also expects an IllegalArgumentException, so wrap UnknownNamedQueryException
throw new IllegalArgumentException(e.getMessage(), e);
} catch (IllegalArgumentException e) {
throw e;
} catch (RuntimeException e) {
throw getExceptionConverter().convert(e);
}
}
Aggregations