1

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. 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).

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?

If it's not, is there a way to retrieve the schema name dinamycally? Even if the datasource is managed by WebLogic/JBoss?

ViniciusPires
  • 983
  • 3
  • 12
  • 26
  • Is the schema you need to query different than the one you are logging in as? Do you have multiple, different schemas you need to query? If not, you can create a public synonym. – OldProgrammer May 15 '15 at 16:46
  • oracle schema == username that you use to login/connect – Sendi_t May 15 '15 at 17:10

1 Answers1

0

you can execute statement alter session set current_schema=SCHEMA; to switch object visibility. but this is DDL statement and does not support bind variable placeholders. I'm afraid that no JPA supports execution of callback statement when connection is withdrawn from connection pool.

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"

ibre5041
  • 4,903
  • 1
  • 20
  • 35