3

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

Mel
  • 5,837
  • 10
  • 37
  • 42
Andrea Caloni
  • 135
  • 2
  • 6

1 Answers1

-1

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.

Mohit Tyagi
  • 2,788
  • 4
  • 17
  • 29