How to check at runtime if a NamedNativeQuery was declared

Viewed 179

In Hibernate, is there a way to check if a given @NamedNativeQuery exists before calling: Session.getNamedQuery("queryName");

I am composing the name of the Query at runtime, so I need a way to find if it exists, in order to avoid the following exception:

MappingException: Named query not known: queryName

1 Answers

Use method getNamedParameters() to check the names of all named parameters of the query.

Update: Currently the only way to check whether a named query with a given name exists is calling EntityManager.createNamedQuery(…) . The non-presence of a query can be expressed by throwing an exception.

Related