JPA Method
in javax.persistence.EntityManagerFactory

void addNamedQuery(
  String name, 
  Query query
)


Define the query, typed query, or stored procedure query as a named query such that future query objects can be created from it using the createNamedQuery or createNamedStoredProcedureQuery method.

Any configuration of the query object (except for actual parameter binding) in effect when the named query is added is retained as part of the named query definition. This includes configuration information such as max results, hints, flush mode, lock mode, result set mapping information, and information about stored procedure parameters.

When the query is executed, information that can be set by means of the query APIs can be overridden. Information that is overridden does not affect the named query as registered with the entity manager factory, and thus does not affect subsequent query objects created from it by means of the createNamedQuery or createNamedStoredProcedureQuery method.

If a named query of the same name has been previously defined, either statically via metadata or via this method, that query definition is replaced.

Parameters:
name - name for the query
query - Query, TypedQuery, or StoredProcedureQuery object
Since:
JPA 2.1