Spring boot application not able to find sequence in AWS Postgresql - java

In existing spring boot application I have created new entity and for the primary key for this entity I have use annotation #GeneratedValue.
Based on entity and annotation I have created required table and sequence in the Postgresql database.(Note, Spring boot and database are existing)
However, while starting spring boot application I am getting error "Unable to build Hibernate SessionFactory Schema-validation: missing sequence", and sequence are created in database under the required schema.
Spring boot application to identify the sequence created in Postgresql and start the application.

In Postgresql DB table, we need to provide privilege (like, insert, delete update) to the user through which spring boot application will connect with DB. So that spring boot application can performed actions like read/write in table/sequence.
For example: DB user mention in application.properties file is dbuser/password, in spring boot application. Then make sure in Postgresql DB side this user, dbuser, should be owner of the the table and have access like, insert, update, delete.

Related

How to see if Spring Boot initializes database?

I would like to put data only when database does not exist on booting Spring boot.
How can I see that?
My application yaml has
...hbm2ddl.auto: update
so I want to see if hibernate did create tables or not in Java code.

Not able to connect to specific schema of aws postgres using spring boot application

I have created an specific schema(example myschema) in aws postgre service and I am trying to connect with my spring boot application. But It is not working. I am successfully able to connect to public schema for aws postgre, but not able to connect with new schema created.
I have tried using below two method:
Appending schema in jdbc url: jdbc:postgresql://xxxxxxxxxx/mydatabase?currentSchema=myschema
But in here my application is performing CRUD in public schema.
I tried to add below two properties in application.properties ,
spring.datasource.hikari.schema=myschema AND
spring.jpa.properties.hibernate.default_schema=myschema
since I am using spring.jpa.hibernate.ddl-auto=validate, property, while starting spring application it is getting failed and showing error like "org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table"
but the table and required objects created.
Kindly suggest me related to this issue.
You have two options:
using of default_schema in application properties
spring.jpa.properties.hibernate.default_schema: my_custom_schema
explicitly specifying schema for each entity
#Entity
#Table(name = "my_table", schema = "my_custom_schema")
You don't need to patch jdbc url in any way.
I use hikari but I've never specified spring.datasource.hikari.schema. It looks redundant

How to connect different databases like Mysql and oracle having same schema, table name and data in spring boot using JPA?

I want to connect 2 different database Mysql and Oracle having same schema, table and data in spring boot JPA. I've configure properties file with 2 different data sources with respective database configuration but i am stuck how to access properties of second data source.

Dynamically create schema in Spring boot application

I have a Spring boot application that uses JPA with Hibernate. It already connect to a primary data source for all transactions.
Now the task in hand is that I need to dynamically create Database Schema in a different database. For instance,
For project 1, create schema 1 in Database X
For project 2, create schema 2 in Database X
Later, these databases will be used by others externally. I am looking for the best way to get this done.
In case of defining multiple datasources in spring boot project, you have to declare associated beans in your configuration. With spring.jpa.hibernate.ddl-auto=create it will automatically create the schema in right database as answered here

update a spring cache when a table update happens through sql procedure

I have a spring boot application with java 8 ,jpa etc and a jboss application with j2ee applications which calls too many sql procedures to update the table.
I have a query something like this in spring boot to get all the employee:
#Cacheable("employeeList")
List{Employee} findByAddressId(Long addressId);
But if someone inserts a new record to Employee table in the same address id from sql procdure from jboss application, the spring boot application is not able to pick the new records , because the query is so generic to that address id.
So i want to create a trigger on that table on insert and update , so when ever insert/update happens it should update the cache with new records belongs to that address id.
Can somebody please tell me how to do this?
If I understand the question correctly you have a spring boot app and a separate jboss app that are connecting to the same database and are insert/updating to the same database tables.
With spring's #Cachable you need to be able to tell spring when you should evict the cached item. For example, having the method that updates the entity being marked as #CacheEvict is an easy way to evict the entity from the cache. The problem here is that if the jboss app updates a record there is no way for spring boot app to know this.
Using a database trigger would seem problematic since you'd have to somehow have the db trigger communicate to the spring boot app to allow eviction to happen.
One solution may be having both the jboss and spring boot app use a distributed caches, like ehcache with terracotta.

Categories

Resources