Spring boot - connect hibernate with one oracle huge table - oracle

I am creating a spring boot application and I only have one table in my oracle database (one table with more than 80 fields...), so, what is the best way to implement this in my spring boot-groovy app?
Do I need to have one entity with 80 attributes??
Can I have a hibernate entity model different from the awful oracle model? (having more than one entity in my app but connected with the same huge table).
Any ideas or tools are more than welcome.

Related

Multiple databases (Postgresql in RDS) but same spring repository and entity

I have a use case where I need to create exact same postgresql database in two different regions. Everything is same in these two databases i.e same schema and same tables and same data.
I have a use to achieve distributed transaction. So if a request land in region-a and write to region-a database to let's say Person table, then exact same record must be either written in Person table in both these database or if there is any error, write attempt should be rolled back.
I am trying to figure out if I can attach two different datasources with same Person Entity and CRUD repository in spring so the respoistory.save() method can write to Person table in both the databases.
So far, I have come across AbstractRoutingDataSource but that is for achieving multi tenancy in the databases. Other solutions are found are slightly different where use case is to write different records in different database (mostly sharding based on various data points).
Does spring provide any out of the box solution so I can achieve transactional write to same table in two different databases.
Does spring provide any out of the box solution so I can achieve transactional write to same table in two different databases.
Depends on your definition of "out of the box" - it doesn't itself implement distributed transactions, but does have support for using libraries that do. It is however relatively complicated to get everything working correctly, and requires additional components to be carefully configured in your runtime environment.
Spring Boot 2.x documentation on distributed transactions is here: https://docs.spring.io/spring-boot/docs/2.7.x/reference/htmlsingle/#io.jta
The Spring Boot 3.x documentation is here: https://docs.spring.io/spring-boot/docs/current/reference/html/io.html#io.jta but it's also worth noting that for 3.x, the Spring Boot team have changed direction and decided that integrated support should be provided by the relevant JTA provider (cf. https://github.com/spring-projects/spring-boot/issues/28589 ), and so there's projects like https://github.com/snowdrop/narayana-spring-boot

How do I fetch data from an existing Oracle Database in spring boot project?

I am creating backend for my CRUD application and I have an existing ORACLE DATABASE. I just want to fetch data from it but I 've seen so many tutorials and in every tutorial they are creating new table in the database by using #table annotation which I don't need ? So if anybody knows about this I could use some of his/her help in this problem?

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.

How can I re generate a new JPA entity(and a database table in a different database schema) for an existing jhipster project?

How can I generate an entity(and a database table) in a different schema other than the default public schema for an existing Jhipster(4.6.2) project generated with spring boot and AngularJS as the technology stack. [Database - Postgresql]
I am very interested if it is possible. Otherwise one simple way to reach that: you could try to generate the entity using the jhipster command jhipster entity <entityName> --[options] see for more details.
And customize your application to use multiple databases by following this excellent article: https://www.baeldung.com/spring-data-jpa-multiple-databases

connect to database retrieved at runtime using spring + hibernate

I am using spring + hibernate transaction manager in the my project. Initially I am connecting to main database and retrieving several projects in a company, say if there are 200 projects each project will have database associated with it, I want to connect to database associated with the project that is selected by user at run time.
Is there any ideal way to connect to database at run time?
There's a Spring abstraction AbstractRoutingDataSource that has been around for a long time, and that fits your bill
The general idea is that a routing DataSource acts as an intermediary
- while the ‘real’ DataSource can be determined dynamically at runtime based upon a lookup key.
There is a good post and a newer tutorial, where you can learn more details.

Resources