Spring Reactive Oracle, default schema - oracle

Hi all i am facing an issue where Spring reactive r2dbc throws
nested exception is io.r2dbc.spi.R2dbcBadGrammarException: [942] [42000] ORA-00942: table or view does not exist
but i have verified that all the necessary tables are created in the DB.
i realised that DB connection is point to SYSTEM schema.
how to i change the default schema?
Below is my spring properties,
spring.r2dbc.url=r2dbc:oracle:thin://localhost:1521/ORCLCDB
spring.r2dbc.username=system
spring.r2dbc.password=root
spring.r2dbc.name=mycustomschema
sorry oracle noob here!

Related

Migrate Javers audit data across databases

In our project we are implementing Javers to records audits in Oracle , and looking for any API support to migrate audit data from Oracle to PostgreSQL or to Mongo as we need to migrate from oracle to other database in near future.
Please advise

connection checker java class in spring boot using HikariCP

Jboss have a mechanism where by I can execute a connection checker class(OracleValidConnectionChecker) before a connection is checked out from the connection pool. That would be helpful in calling a stored procedure before each DB call.(This is needed for setting security context in DB layer for Oracle Layer Security)
Is there any similar mechanism in spring boot (tomcat) using HikariCP ?
I know that there is a connection checker SQL query config (spring.datasource.hikari.connection-test-query). But I am looking for a way to execute a Procedure with input parameters.
As per https://github.com/brettwooldridge/HikariCP#configuration-knobs-baby I believe connectionInitSql would make more sense in your case. connectionTestQuery is for "legacy" drivers that do not support the JDBC4 Connection.isValid().
You may be able to construct your own stored procedure query and pass it into this property, however, be wary you will not benefit from the protection prepared statements generally provide eg. sql injection.

MyBatis+Spring+Jersey with Oracle Seems to reuses SQL sessions

I'm creating a rest service using MyBatis 3.3.1, Spring 4.3, Jersey 2.22 and Oracle 12c. My transactions are being managed by Spring using the DataSourceTransactionManager and the #Transaction annotaion. I am also using a MyBatis pooled data source as my javax.sql.DataSource. What I don't understand if why database sessions are being reused.
In my application, I am setting an oracle client identifier: DBMS_SESSION.SET_IDENTIFIER("my id"). With the debug logging statements, I can see MyBatis creating new sessions for each of the MyBatis sql operations. I also have debug to print out the database session identifier from DBMS_SESSION.UNIQUE_SESSION_ID.
What I don't understand is that if I access my rest endpoint multiple times, the unique session id is the same and the identifier from my last access is still set.
Shouldn't a new oracle session be used every time MyBatis gets a new SQLSession? Why is the oracle session always the same?
Thanks.
Session in Oracle is bound to a connection.
You are using connection pooling so after one rest request is finished the connection is returned to the connection pool. Session is not terminated in this case.
You probably want to clear identifier on returning connection to pool and setting it on retrieving connection from the pool. The exact way to do that depends on the connection pool you are using. For built-in mybatis connection pool see this answer.

Weblogic Oracle Service Bus 11gR1 NoClassDefFoundError Hibernate Exception

We have a Business Service which we have imported from a Weblogic OSB 10.3 server into a Weblogic OSB 11gR1 server. The Business Service is an ejb protocol service which basically connects to an Oracle DB and writes messages to a given Table.
When we call the Business Service from a project flow, we are getting the following exception:
java.lang.NoClassDefFoundError: org/hibernate/JDBCException
thus, the messages in the flow are not being written to the database table...
I am guessing that this is due to a wrong hibernate jar version or something along those lines? Where do I need to look and what can I do to resolve this error?
The reason for why we were getting JDBCException was simply because the Oracle tablespace in which the table was sitting under was 100% full and, crucially, the tablespace was not set with autoextend on.

Javers is grabbing all of my available Connections

One other thing I'm finding, is that it appears that Javers is grabbing all of the available Connections out of my connection pool (created via Spring DataSourceBuilder). I'm not using Hibernate/JPA, just straight JDBC via JdbcTemplate and mostly MyBatis for my entity queries.
I've added a logging statement to my ConnectionProvider for Javers, and at the start of the application when it queries for the schema, it pulls 4 connections to check for each of the tables, and then never returns any of them even after the commit from the PlatformTransactionManager.
I understand from https://stackoverflow.com/a/35147884/570291 that it's supposed to participate in the same connection as the current Transaction. Since I'm not using Hibernate/JPA, does that mean I need to implement the connection tracking/etc from MyBatis to the Javers ConnectionProvider to return the same connection (if there is one), and then handle closing (returning to the pool) of that connection at the end of the transaction?
I found DataSourceUtils.getConnection(DataSource) which is a Spring utility class to get a connection from the given DataSource including if it's tied to a current transaction or not as appropriate. Using that in the ConnectionProvider looks like it's done the trick of keeping the connection for the existing transaction.
JaVers won't return connections to application's connection pool for the same reason as it won't call sql commit or rollback.
Managing connactions and transactions is the application's responsibility, not JaVers. We call it passive mode, from Javers doc:
- JaVers doesn’t create JDBC connections on its own and uses connections provided by an application (via ConnectionProvider.getConnection()).
- JaVers philosophy is to use application’s transactions and never to call SQL commit or rollback commands on its own.
Thanks to this approach, data managed by an application (domain objects) and data managed by JaVers (object snapshots) can be saved to SQL database in one transaction.
In JaVers project there is no mybatis support, so you need to implement ConnectionProvider for mybatis on your own.
Proper implementation of ConnectionProvider shouldn't create new sql connection for every getConnection() call. It should return the connection which underlies current application's transaction. Typically, it's implemented using ThreadLocal.
As you mentioned, ConnectionProvider should handle committing transactions and closing connections.

Resources