In my project we are using oracle database as the main application db and H2 as in memory database to run only the integration test cases. Oracle db has many functions which are of the structure "schema.package.function()". The problem is, i'm not able to recreate the same function in H2 for integration test cases as H2 treats it in the form of "dbname.schemaname.functionname()".
for example : When code runs with oracle db , "SELECT MDM.NEXT_KEYS.NEXT_REF_SOURCE_KEY from dual" works. During integration test case on H2, it throws error "DB MDM not found". So i set the db name as MDM and schema name as NEXT_KEYS in h2 setup.It worked. But my next function PAYERS.KEY_TRANSLATIONS.CORE_ENHANCED_DESC_4_KEY fails now saying "DB PAYERS not found".
Changing the oracle functions is out of the equation as they are used by multiple teams.
If this is not possible with H2 , can you suggest a good alternate in-memory db for spring boot
Appreciate your help !
I was able to fix the issue. Adding the solution link here so that it might help someone
Setting this flag IGNORE_CATALOGS=TRUE fixed the issue. When it is enabled, name of catalog (database) is ignored.
spring.datasource.url = jdbc:h2:mem:testdb;MODE=Oracle;IGNORE_CATALOGS=TRUE
Refer the below link https://github.com/h2database/h2database/issues/2893
Related
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 surprised I haven't found an SO question that answers this. I am trying to connect a springboot/JPA application to an SQL Server on my local machine. I have the application setup so that it can connect to a database if it it exists, but if I change the JDBC URL to create the database if it doesn't exist then it fails. Here is what the properties look like when it fails.
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=testing;createDatabaseIfNotExist=true;
spring.datasource.username=hello
spring.datasource.password=Hello1234
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.database-platform=org.hibernate.dialect.SQLServer2008Dialect
spring.jpa.show-sql=true
Here is a snippet of the error I receive when starting the app:
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user
'hello'. ClientConnectionId:971a3369-258b-4713-bddc-cda559b9fe94 at
com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:262)
~[mssql-jdbc-8.4.0.jre11.jar:na] at
com.microsoft.sqlserver.jdbc.TDSTokenHandle
If anybody has any thoughts as to how I can change this so the database is created if it does not exist I would be very thankful. Thanks in advnace.
I don't think a database can be created using JPA.
It has to be created manually or in some other ways, but JPA won't do that for you.
And it would be a bad practice as well to create the database using the application itself, and the use of same credentials.
Yes, definitely you can auto-create a database with JPA for that
spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=testing;
createDatabaseIfNotExist=true;
line should be changed to:
spring.datasource.url=jdbc:sqlserver://localhost:1433
/testing?createDatabaseIfNotExist=true
In practice your application should never create your database so its not really a problem most of the time(Outside small databases like sqlite3). Different databases would handle this situation differently as well.
In your case I do not see this as a valid jdbc parameter in the documentation.
I would recommend creating the database in advance with a privileged user separate from your application user.
Running spring-boot 2.1.3.RELEASE and using liquibase 3.6.3 on Oracle 12.1.0.2.v15, I get exception on startup:
Did not update change log lock correctly.\n\n 0 rows were updated instead of the expected 1 row using executor oracle there are 0 rows in the table
This:
https://github.com/liquibase/liquibase/blob/master/liquibase-core/src/main/java/liquibase/lockservice/StandardLockService.java#L334
Investigating, I suspect it might be related to some missing right of my user as it works fine on a database created with AWS RDS 12.1.0.2.v15 but not on the on premise database.
The only noticeable difference is that the user for on premise has no access to v$parameter so I get:
Could not set check compatibility mode on OracleDatabase, assuming not running in any sort of compatibility mode: Cannot read from v$parameter: ..
Has anybody an idea ?
Can it be related to autocommit default value ?
Any link to requirements for Oracle user when using liquibase ?
So the issue ended up being an Oracle user misconfiguration by DBA, he had no privileges on tablespace.
But this issue didn't appear in logs.
Once I removed liquibase context:
spring.liquibase.contexts
The issue appeared clearly:
ORA-01950 : no privileges on tablespace ....
I am creating a Hibernate project in IntelliJ IDE and trying to hook it up with a H2 database. I created the project based upon this tutorial:
http://www.roseindia.net/hibernate/hibernate4.2/hibernate-example-step-by-step-in-eclipse.shtml
The only change I'm making is the database, instead of MySQL, I'm using H2. However, when I'm trying to run the application, the insertion to the database is shown to have been successful, but there are no signs of any such rows when I open up the database in the H2 console. I've tried many solutions suggested here and elsewhere, including this, this and this. I've tried changing the connection URL of the database in the hibernate.cfg.xml file from a relative path to absolute path, but to no avail. I'm attaching a screenshot of my hibernate.cfg.xml and the relevant portion of the log below. Please help me out with this.
your hibernate.connection.url should be something like that jdbc:h2:tcp://localhost/mem:playground I am assuming you are starting the H2 database out of your project, as you are connecting to H2 via console.
In my J2EE 5 application I have a JDBC Realm based security with Form method. Encrypt method is MD5 as default.
The database is PostgreSQL 8.4 installed locally (or 8.3 available via lan).
My app used to work finely on GlassFish v2.1 server with PostgreSQL 8.3, but now I need to deploy it on GlassFish v3.
I am absolutely sure I have done all the same config on GFv3 like creating Connection Pool (which pings with no problem), JDBC Resource and JDBC Realm.
But on GFv3 I get login exception with "invaliduserreason" while the database schema is just created from the working database script.
I have checked the data and entered login/password thousand times and it seems that data is all right.
So where can I find the reason of unworking security? Please, advice.
NetBeans 6.8
Thanks.
I had the same issue here.
I resolved setting the security log to finest.
I saw that jaas was querying the db in lowercase even though I used a camel notation in naming my fields in postgresql table.
The only solution I found was to name all my table and fields in lowercase in Postgresql server as well.
You might want to increase the logging for the security system. Go to Logger Settings -> Log Warnings and set logger name 'javax.enterprise.system.core.security' to trace. Try again and check the logs.
Try changing database tablenames to UPPERCASE. I had the exactly same problem as you have and changing tablenames to uppercase solved the problem for me.
Setting Digest Algorithm to "none" worked for me. I am using Glassfish 3.1 with Derby. In realm config i have name of tables in lowercase and userid and groupid are columns in the same table, so these things do not cause problems on Derby.
Here is a nice article about jdbc security realm in glassfish and how to configure it: http://jugojava.blogspot.com/2011/02/jdbc-security-realm-with-glassfish-and.html
try adding database name to the property Url in your connection pool.. the sqlexception hidden here states that database name is not specified.. worked for me