简体   繁体   English

使用容器托管数据源执行Oracle本机查询

[英]Executing a Oracle native query with container managed datasource

I have a project using JPA's <non-jta-datasource> in persistence.xml to connect to a container-managed Oracle Datasource, and I have to use in some point a native query that is built dynamically. 我有一个项目,在persistence.xml使用JPA的<non-jta-datasource>连接到容器管理的Oracle数据源,并且在某些方面必须使用动态构建的本机查询。 By default in Oracle I need to specify the schema in the table name to make a query, but I don't have access to the schema name (and shouldn't). 在Oracle中,默认情况下,我需要在表名称中指定schema以进行查询,但是我无权访问架构名称(也不应)。

First of all, is this an expected behavior? 首先,这是预期的行为吗? If I execute SELECT * FROM TABLE should Hibernate rename it to the Datasource parameters and execute SELECT * FROM SCHEMA.TABLE instead? 如果我执行SELECT * FROM TABLE ,Hibernate应该将其重命名为Datasource参数,然后执行SELECT * FROM SCHEMA.TABLE吗?

If it's not, is there a way to retrieve the schema name dinamycally? 如果不是,是否有办法以动态方式检索架构名称? Even if the datasource is managed by WebLogic/JBoss? 即使数据源由WebLogic / JBoss管理?

you can execute statement alter session set current_schema=SCHEMA; 您可以执行语句alter session set current_schema=SCHEMA; to switch object visibility. 切换对象可见性。 but this is DDL statement and does not support bind variable placeholders. 但这是DDL语句,不支持绑定变量占位符。 I'm afraid that no JPA supports execution of callback statement when connection is withdrawn from connection pool. 从连接池中撤出连接时,恐怕没有JPA支持执行回调语句。

Usually when you want access object from other schema and you do not want to use schema prefix, then you create synonyms in your schema. 通常,当您想从其他架构访问对象并且不想使用架构前缀时,则可以在架构中创建同义词。 This is a usual way how to solve such a "problem" 这是解决此类“问题”的常用方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM