Liquibase execution order in Spring Boot - java

I was using spring-boot 1.0.1 and everything was fine.
Than I needed to upgrade to latest version 1.1.8.
As I see something with liquibase is changed and I cannot run application in the development mode normally.
The problem is that before updating first Hibernate was creating tables and performing database things, then Liquibase. Now Liquibase runs first and complains that there is no tables.
Is there a way how to solve this?

Related

Jhipster projects keep trying to use wrong database

I'm trying to develop some test projets using jhipster but I'm facing a problem.
I've choosen to use H2 in memory in develop mode and postgresql for production.
When I start the project in dev mode, it looks for postgres db and also for a db with the wrong name.
Also, every single project looks for the same db, but I can't find the properties with that db name.
I tried a projects using postgres also in dev mode and it works, but using always that database!
I tried to debug every single row but I couldn't find where the code find that url.
I found out that it sets it in DataSourceBuilder url.
Do you have any ideas?
Thank you
I solved my problem.
I had set some spring datasource configurations in my Windows environment variables.
That's why each project ignored its own properties.

Spring boot start up Building JPA container very slow

I am using Spring Boot with JPA and it has recently started to take a long time to start up. It always gets stuck on this line in the console for about 5 minutes:
Building JPA container EntityManagerFactory for persistence unit 'default'
I have seen this related post:
Very slow Spring Boot application startup
And have tried adding spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false to my application.properties
But this made no difference at all.
Is there any way to debug what spring boot is actually doing during this time?
My gradle dependencies are as follows:
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-tomcat')
compile('org.springframework.boot:spring-boot-starter-data-redis')
compile('org.springframework.boot:spring-boot-starter-mail')
compile('org.springframework.session:spring-session:1.3.1.RELEASE')
compile('mysql:mysql-connector-java')
compile('org.apache.commons:commons-lang3:3.7')
compile('com.google.cloud:google-cloud-storage:1.14.0')
compile('javaxt:javaxt-core:1.8.1')
compile('org.hibernate:hibernate-envers:5.0.12.Final')
testCompile('org.springframework.boot:spring-boot-starter-test')
And I am using Spring Boot version 1.5.9.RELEASE
My application.properties has this:
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://notreal.server.com:3306/testdb
spring.datasource.username=NotRealUser
spring.datasource.password=NotRealPwd
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
Any suggestions / help much appreciated.
I managed to fix my problem by setting spring.jpa.hibernate.ddl-auto=none in my application.properties (previously set to auto).
I think this prevents Hibernate trying to compared object models with tables in the database. Springboot start-up was much quicker afterwards.
I should mention that around then we also added Hibernate Envers (auditing framework) to the project which generated a bunch of new tables in the database. So this probably compounded the issue.
Had the same issue within Hashicorp Nomad. Would apply on any system that allocates memory.
If you look at the system logs (not Spring Apps) you will see this step is more memory intensive. Increase memory for the application and it should run with spring.jpa.hibernate.ddl-auto=auto

Spring boot application startup stuck loading hibernate files

I am using spring boot application with hibernate to connect to postgressql, but when I am running my application with run as spring boot app the starting of server is stuck with loading hibernate files
without any error, I am stuck on this and it's not also showing any error.
Does anyone have any idea?
Add the following to your app properties
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
or in your code the below
properties.setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false");
Hope it helps!
There was another instance of Postgresql server was running and i was also not able to kiss the process that's why the application was stuck, i restarted my system and its working fine
If you are using JPA, check your repository configuration. Spring can spend a very long time scanning for JPA repositories if you don't have basePackages or basePackageClasses set in your #EnableJpaRepositories annotation (this can be added by JpaRepositoriesAutoConfiguration if your setup meets that class's #ConditionalOn requirements).

Spring Auto configuration resulting in old MySQL dialect

I created a small POC app with spring boot, using hibernate (5.2.9) and maria db (10.1.19).
I had some sql dialect issues where my create/drop table SQL was using type=MyIasam but resolved that locally by setting the spring.jpa.properties.hibernate.dialect, however, when I deploy to the cloud (PCF) all of the cloud profile stuff kicks in, and I end up with hibernate deciding its dialect is going to be org.hibernate.dialect.MySQLDialect
this results in invalid SQL getting generated for creating new tables.
Note that I'm not really sure what else could be happening. This is a spring boot app (1.5.3) and the cloud profile is kicking in to do auto configuration. There's a bunch of properties injected. And I can't seem to get my dialect property to be respected.
This is a solid crushingly easy problem that is the escaping me.
Any ideas what I need to set, or provide as dependencies?
I tried removing all of the mysql dependencies, but then the connection string inject is jdbc:mysql... which i think may be part of the problem...

How do I mimic Hibernate hbm2ddl "create" behaviour in Liquibase?

I've worked with liquibase 1.9.5 for a while now and got it to replace hibernate hbm2ddl strategy of creating tables and loading fixtures in it. Since it's a maven project and since I use hsqldb (using file create=true), I simply create the db in the target folder so that I have a fresh database anytime I test the application. Works fine till that I realize:
1 I will need the database to be recreated when doing integration test using mysql database now
2 I will definitely need the same solution for a non maven project.
So basically how do I drop and create the database when using liquibase as opposed to hbm2ddl?
The easiest way is to add a separate database call before liquibase update that runs the sql
DROP DATABASE X;
CREATE DATABASE X
Liquibase does have a dropAll command which can be used to drop everything in a schema, but it is slower than drop/create database on mysql and may miss some database objects.

Categories