Manage @NamedNativeQuery and schema

前端 未结 2 1996
独厮守ぢ
独厮守ぢ 2021-01-19 04:04

I have many EntityManager, one per schema that I have (I use entity-mappings file to map EMs with schemas). It works.

When I use @Nam

2条回答
  •  滥情空心
    2021-01-19 04:36

    Excerpts from documentation :

    • NamedNativeQuery : Specifies a named native SQL query. Query names are scoped to the persistence unit.
    • NamedQuery : Specifies a static, named query in the Java Persistence query language. Query names are scoped to the persistence unit.

    It isn't specified directly that NamedNativeQuery is static, but both are same scoped & can't be altered afterwards & it's the desired behaviour.

    Named queries are mean to be accessed by multiple modules - application wide, identified by unique name, so they are static & constant. You can try building a query string dynamically & can create a native query from it, instead of named native query.

提交回复
热议问题