我在工作中使用 OpenJPA。有时我必须使用 JPQL,有时我必须使用本机查询(em.createNativQuery)。
我目睹了本机查询的一个大问题。我也必须提供架构名称。
就像 JPQL 我可以写:
em.createQuery("Select e from Entity_name e").getResultList();
但在本机查询的情况下,我需要这样做:
em.createNativeQuery("Select e from SCHEMANAME.Table_name e").getResultList()
为什么会这样?这不是错误的行为,因为模式名称可能会随时间而变化。