HSQLDB ROWNUM compatibility with Oracle - oracle

THe HSQLDB changelog states that ROWNUM() was added in v2.2.0 which I am using without any problems when running integration tests against the in-memory HSQLDB.
However I want to run the same tests against a real Oracle 10g database, but the query fails because the pseudo-column is called ROWNUM. Is there an easy way write a single query string that works in both environments?

The ROWNUM() function is available by default in HSQLDB 2.2.x and later. If you enable Oracle syntax compatibility mode, you can also use ROWNUM.
This statement enables it:
SET DATABASE SQL SYNTAX ORA TRUE
Or use the connection property sql.syntax_ora=true

Related

Spring Batch Meta-Data Schema for Oracle

Where can I found the sql to create in my database all the metadata sctructures needed by The Spring Batch framework.
The application don't have the permission on the database to outgenerate them.
As suggested in the documentation I've try to use the sql provided in the org.springframework.batch.core repository
but it's seems to be uncomplete.
For example it misses the column BATCH_JOB_EXECUTION .JOB_CONFIGURATION_LOCATION VARCHAR(2500), which on the other hand it's present in the documentation snippet
I've understand that this structure comes with the newest vesion 4.1 but also the (migration script)[https://github.com/spring-projects/spring-batch/blob/main/spring-batch-core/src/main/resources/org/springframework/batch/core/migration/4.1/migration-oracle.sql] doesn't seem to be right since it supposed that the column it's already there:
ALTER TABLE BATCH_JOB_EXECUTION MODIFY JOB_CONFIGURATION_LOCATION VARCHAR2(2500 char);
Where can I found the complete oracle sql script that creates the structure needed by the framework version 4.3.6 ?
If you look at https://github.com/spring-projects/spring-batch/blob/4.3.x/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-oracle10g.sql you can see the BATCH_JOB_EXECUTION.JOB_CONFIGURATION_LOCATION column. So you can use /org/springframework/batch/core/schema-oracle10g.sql from the classpath since it is included in spring-batch-core-4.3.6.jar.

Spring Integration Testing Oracle Native SQL

I have a legacy application that has recently been ported from Struts to Spring MVC. The data layer is written with native Oracle SQL. I'd like to introduce some integration testing but would like to avoid using an actual Oracle database for obvious reasons. Is there an in-memory DB that can deal with Oracle native SQL? Is this just a dream? Am I just going to end up with Oracle XE in a VM?
I've discovered that H2 actually has an Oracle compatibility mode. Great!
spring.datasource.url=jdbc:h2:mem:testdb;Mode=Oracle
spring.datasource.platform=h2
spring.jpa.hibernate.ddl-auto=none
spring.datasource.continue-on-error=true
Isn't Oracle's in-memory database, TimesTen, compatible with standard Oracle?

Hibernate dialect Issues with update to Oracle 12.2 C database when using Grails

We are running Grails 2.3.11 on JRE 1.8_211. We have Hibernate version - 3.6.10.6.
When we were working with Oracle 11, it was working fine but when I upgrade to 12.2C, we get following error:-
org.codehaus.groovy.grails.orm.hibernate.exceptions.CouldNotDetermineHibernateDialectException: Could not determine Hibernate dialect for database name [Oracle]!
On reverting back to Oracle 11, the issue gets resolved.
Can anyone please suggest a solution for migrating my application to Oracle 12.2C.
We had not specified the hibernate dialect in one of the datasources in datasource.groovy.
It seems that in oracle 12C, it is mandatory to specify the dialect for each data source even though it is not mandatory for Oracle 11g.
Hence, during migrating from Oracle 11g to Oracle 12C, please add verifying that dialects are explicitly specified in your checklist.
Hope this helps others.

Spring boot - h2 and Oracle no 100% compatibility

I am using H2 in Spring boot app and Oracle DB on production.
For checking migration files I use FlyWay.
Unfortunately, H2 isn't compatible with Oracle (even if is set Oracle mode).
So, I can't validate my migrations files.
When I have a H2 query - validation in my project is ok, but when I upload it to production - it won`t work on Oracle.
Have you got any ideas how can I validate oracle migration files on my h2-db project?
The Flyway FAQ covers this under db specific SQL:
You can use the flyway.locations property. It would look like this:
TEST (Derby): flyway.locations=sql/common,sql/derby
PROD (Oracle): flyway.locations=sql/common,sql/oracle
You could then have the common statements (V1__Create_table.sql) in common and different copies of the DB-specific statements (V2__Alter_table.sql) in the db-specific locations.
Another approach if the differences are really minor ie only a few keywords, would be to have the keywords that differ as Flyway placeholders:
ALTER TABLE table_name ${alter_column} COLUMN column_name datatype;
TEST (H2): flyway.placeholders.alter_column=ALTER
PROD (Oracle): flyway.placeholders.alter_column=MODIFY

Table not found after apparently successful migration

I was using flyway through the CL to migrate my production DB (mySql), while I was using a fixed SQL query to create the DB, tables, etc. in my unit tests, using H2. I'd like now to better integrate flyway and create/delete DB after each unit test.
I have a DB factory and inside its build method I'm using the following code:
flyway.setLocations("filesystem:sql/migrations/common","filesystem:sql/migrations/h2");
flyway.setSchemas("MYSERVER");
flyway.setDataSource(
p.getProperty(DB_URL.getName()),
p.getProperty(USERNAME.getName()),
p.getProperty(PASSWORD.getName()));
flyway.setInitOnMigrate(true);
flyway.migrate();
The migrations seems to apply correctly, as I can see my SQL code from the flyway logs. But when I start using the DB, immediately afterwards, I get TABLE NOT FOUND errors. I'm using h2 as in memory DB with the following URL to initialize my client:
jdbc:h2:mem:MYSERVER;MVCC=true
Do you have any idea on what I might be making wrong?
The problem is your JDBC url.
MYSERVER is the name of the database, not the schema.
The easiest thing to do is to let flyway use the same url, and not set a schema. This way you'll find everything in the public schema of the MYSERVER database.
Having the same issue - after digging around, it appears that the H2 database is being recreated between migration scripts somehow.
You can confirm this happens by putting a SELECT * FROM migrations in the first two migrations - it will succeed in the first and fail in the second.
According to the H2 Documentation, specifying a database name and ;DB_CLOSE_DELAY=-1 option should suffice to allow concurrent and subsequent accesses to the in-memory database, however this is not the case.
Upgrading Flyway from 3.1 to 3.2.1 has fixed the problem.

Resources