Managing @NamedNativeQuery and Schema

I have a lot of EntityManager , one per schema that I have (I use the entity-mappings file to map EM to schemas). He works.

When I use @NamedQuery , it works like a charm, but when I use @NamedNativeQuery , the scheme is not used. I have to go with him SELECT foo FROM schema.table .

Is this the right behavior?

I think the @NamedNativeQuery parameter cannot parametrically pass the schema (I believe that only columns can be dynamic, not tables or schemas or anything else), since I can use @NamedNativeQuery with a dynamic schema, please?

+4
source share
2 answers

Excerpts from the documentation:

  • NamedNativeQuery: Specifies a custom SQL query with a name. Query names are bound to a storage unit.
  • NamedQuery: Defines a static named query in the Java Persistence query language. Query names are bound to a save node.

It is not directly stated that NamedNativeQuery is static, but both are the same and cannot be changed later, and this is the desired behavior.

Named queries have access to several modules - a wide application scope, identified by a unique name, so they are static and persistent. You can try to build the query string dynamically and you can create your own query from it, instead of the name of the native query.

+2
source

Your table name prefix "{h-schema}", for example SELECT foo FROM {h-schema}table

(kindly provided programmatically to get the default sleep scheme name from a factory session? )

+5
source

All Articles