本文介绍了管理@NamedNativeQuery和架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多EntityManager,每个模式都有一个(我使用entity-mappings文件将EM映射到模式).可以.

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

当我使用@NamedQuery时,它的工作方式就像一种魅力,但是当我使用@NamedNativeQuery时,则不使用架构.我必须具备SELECT foo FROM schema.table的资格.

When I use @NamedQuery it's working like a charm but when I use @NamedNativeQuery schema is not used. I have to qualify with it SELECT foo FROM schema.table.

这是正确的行为吗?

我认为无法通过参数@NamedNativeQuery动态传递模式(我相信只有列可以是动态的,而不能是表或模式或其他任何东西),那么我如何将@NamedNativeQuery与动态模式一起使用?

I think it's not possible to parameter @NamedNativeQuery to dynamically pass schema (I believe only columns can be dynamics not tables or schemas or anything else) so how can I use @NamedNativeQuery with dynamic schema please ?

推荐答案

文档摘录:

  • NamedNativeQuery:指定一个命名的本机SQL查询.查询名称的作用域是持久性单元.
  • NamedQuery:用Java Persistence查询语言指定静态的命名查询.查询名称的作用域是持久性单元.
  • 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.

没有直接指定NamedNativeQuery是静态的,但是两者的作用域都相同&此后不能更改这是期望的行为.

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.

这篇关于管理@NamedNativeQuery和架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 11:02