Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
None
-
None
-
None
-
Oracle database
Description
It is very common in production environments to use two distinct database users, one to connect to the database and one for table ownership. When setting up the datasource, for example as JNDI resource in Tomcat's context.xml file, an "initSql" setting is used to switch the current database schema. For Oracle this can be done using the following SQL:
alter session set current_schema = TABLE_OWNER_SCHEMA
When using this setup, Jackrabbit's check for table existance in org.apache.jackrabbit.core.util.db.ConnectionHelper.tableExists() fails because it assumes that the connect-user, retrieved by connection.getMetaData().getUserName(), is equal to the current database schema.
The right way to retrieve the current database schema for Oracle is either to execute the SQL statement
select sys_context('userenv', 'current_schema') from dual
or to get it from JDBC connection by calling
connection.getSchema().
The latter has been introduced in JDBC 4.1 or JDK 7 and has the disadvantange that many JDBC drivers still throw an AbstractMethodError to indicate 'Not implemented yet'.