Does Spring-Data-JDBC support Oracle identity columns? - spring-data-jdbc

I'm trying to save into a table with an Oracle identity field (it's some sort of auto increment). But as soon as I do that I get an "identity must not be null after save" exception ?
Is this scenario currently not supported or do I need a special config ?
BTW: it's works with JPA.

Yes, your assumption is correct.
Spring Data JDBC currently does not identity fields with Oracle Databases.

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.

what is the best way to create session from java spring boot using oracle Database?

I created user in oracle database and I am trying to create session but I find many ways in spring boot so what is the easy way if I want to create classe connections using the Username and Password ?
You can jdbc template, spring data JDBC or spring data JPA, well depending on your use case.
If your data model is quite complex, you should avoid using the JDBC template as you will need to write prepared statements which can be cumbersome. JPA will allow you to use object-oriented programming principles and also will help you map the entities to your database columns.
For example, if you are going to use spring data JPA, you need to set the application properties as follows:
spring.datasource.type=oracle.oracleucp.jdbc.UCPDataSource
spring.datasource.oracleucp.connection-factory-class-name=oracle.jdbc.pool.OracleDataSource
spring.datasource.oracleucp.sql-for-validate-connection=select * from dual
spring.datasource.oracleucp.connection-pool-name=UcpPoolBooks
spring.datasource.oracleucp.initial-pool-size=5
spring.datasource.oracleucp.min-pool-size=5
spring.datasource.oracleucp.max-pool-size=10
This would behind the scene create an Oracle Datasource. In this example, we are using Oracle Universal Connection Pooling. You can also use HikariCP which is quite popular.
check this out
If you want to use UCP with above properties then you must have SpringBoot version higher than 2.4.0.
Check out the Spring Boot code sample on GitHub.

spring boot hsqldb details

I have created two spring boot microservices for experimenting purposes, both use hsqldb. Is there a way to see the hsqldb details like what is the name of the db that spring boot created, username, password, what tables are there in each one and to query those tables.
You can use the built-in SQL functions and INFORMATION_SCHEMA views in HSQLDB to check these properties. See the Guide http://hsqldb.org/doc/2.0/guide/
But the quick and easy way is to use a file: database connection and check the *.script file of the database, which contains SQL statements that set the properties and create the tables.

jdbc data independence without using hibernate api?

I am trying to solve problem by using properties file but in properties file we can handle only database driver problem.if we want to mysql to oracle database need to change all my query.the problem is now how to make query independent without hibernate api?? please suggest

Change the Hibernate database schema at run time in spring boot application

I have A requirement where the current schema to be used is stored in db table;(schema_a or schema_b).
The application is loaded with default schema
spring.jpa.properties.hibernate.default_schema=schema_a
Now when the data in table is updated to B I want to consider all jpa query to use schema_b without any down time at server.
Your question is not clear enough to provide some code to your question, but you can catch inspiration from the following articles:
https://spring.io/blog/2007/01/23/dynamic-datasource-routing/
Spring Boot - Change connection dynamically

Resources