How to see if Spring Boot initializes database? - java

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.

Related

Configure spring batch without persisting metadata

I need to to change the spring batch application where I don't need to persist in the spring batch metadata tables, instead I need to use the in memory metadata.
My application is not Spring-Boot application, and I am using java configuration for spring.
Also I need to persist into the application tables so I need to use datasource.
Add in-memory DB to your Gradle project dependencies, for example, h2 :
compile 'com.h2database:h2:1.4.194'
Batch automatically will store the metadata in h2.

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

is it possible to create database schema using spring boot with JPA

is it possible to create database schema using spring boot with JPA in postgresql through java coding? like we are creating tables using spring boot with JPA.
Yes you can do. Please refer the Spring Documentation.
Database Initialization

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.

Loading initial data at application startup with Spring Data MongoDB

I use embedded MongoDB database in a development environment. It is setup empty at the application startup. I would like to load initial data which is needed for the application when the Spring context is setup.
Is there a way in Spring Data MongoDB to point a JSON file(s) which would be loaded into a database (something like import.sql (hibernate.hbm2ddl.import_files) in Hibernate or #UsingDataSet in NoSql Unit)?
mongeez see wiki link for spring integration wiki

Categories

Resources