I am using EclipseLink with Oralce DB and would like to get database name, schema version and url via EntityManager. I have already tried solution mentioned in following question
Getting a JDBC connection from EclipseLink
But this approach is not working for me and I have mentioned the problem in following question:
Getting sql connection via EclipseLink
I would like to know how can I get the required data directly via native query. I have an instance of entityManager and using it, I can execute native queries and get what I want
Related
I'm attempting to set a custom (non-PUBLIC) schema for my HyperSQL database which I connect to with the Tomcat JDBC driver. I can't seem to get the connections to not use 'PUBLIC'.
I've tried setting various URL parameters and the 'connectionProperties' in the PoolProperties; example:
jdbc:hsqldb:hsql://localhost:0/test;currentSchema=schemaTest
We have a Java application (basically integration tests) that uses Hibernate (which uses Jdbc) to read/write data to the MySQL Database. Hibernate objects like sessions or transactions are created and configured via our own code (no Spring or other wrappers are being used). The issue is that periodically (multiple times during tests execution) we observe a "No database selected" exception. Database URL that we use for DataSource configuration already contains database name in it:
jdbc:mysql://localhost:3306/test?useSSL=false&createDatabaseIfNotExist=false&cacheServerConfiguration=true&cacheResultSetMetadata=true&useLocalSessionState=true&rewriteBatchedStatements=true&tcpNoDelay=true&tcpTrafficClass=16&alwaysSendSetIsolation=false&tcpSndBuf=1048576&tcpRcvBuf=1048576&characterEncoding=utf8&allowPublicKeyRetrieval=true
I tried to catch the Exception and test the connection's selected database by running select database() and it actually reports that the value is null on the database side.
Even more strange thing is that next queries on the same connection are executed against the normal database (so it somehow self-heals).
Does anybody know why can MySQL connections "lose" and then "restore" selected database?
Or maybe there is a way to trace the problem down. Will be grateful for any help or thought that you can provide
Versions:
Java 1.8.0_292
Mysql 5.6.31
Hibernate 5.4.2
JDBC mysql-connector-java 8.0.22
I am using HSQLDB for JUnit Tests, the test data is provided by XML Files with dbUnit. Our application uses an Oracle DB in production.
In order to suppert Oracle-specific queries I have added the property sql.syntax_ora=true to the url like this:
db.url=jdbc:hsqldb:mem:unitdb;sql.syntax_ora=true
When I run my JUnit test I get the exception
org.hsqldb.HsqlException: The table data is read only
I have also tried to execute the query SET DATABASE SQL SYNTAX ORA TRUE;
but this gives me the same exception.
Please help me with this problem. Thanks!
In my current project, I am doing migration from Oracle to Azure SQL Server. Right now, we need to integrate both database working with same queries. Depending on what I have on my configuration, project will connect with Oracle or Azure SQL.
Problem is, there are some queries that are not compatible for both database types. For instance, nextval works for Oracle, but not with Azure SQL:
In Oracle:
... values(unique_id_seq.nextval ...
In Azure SQL:
... values(NEXT VALUE FOR unique_id_seq, ...
Therefore, I think I will need to create two different queries and my project should know which database I am loading and it should map to correct query. Is this possible to achieve in springboot? I am pretty new to springboot..
(One of my co-worker said If possible try to convert query into HQL or add the mapping entity, instead of creating separate queries., but I am not sure what this means.)
Try using Spring Boot with Hibernate.
I have developed spring-boot microservice and for Database interaction I am using jdbcTemplate. Currently I am placing all my queries in application.properties as below:
sql.select.query=update SCHEMA.TABLE_NAME set COL_NAME='ABC' where COL2_NAME='XYZ'
and in Dao Layer, Iam using this variable for query.
#Value{sql.select.query}
private query;
The above piece of code is fine and running as expected but now the requirement came up that Schema name should be segregated from query so that in future it can be changed.