How to edit Hibernate settings in a Spring-Boot project? - spring

Essentially what I'm trying to do is to add this property change to hibernate so I can enable instantiation of composite/embeddable objects when all of its attribute values are null:
hibernate.create_empty_composites.enabled
I am aware that the usual way to edit Hibernate is in the application.properties file like so:
################################################################################
# JPA MANAGEMENT #
################################################################################
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true...
...
spring.jpa.properties.hibernate.create_empty_composites.enabled=true
But the spring.jpa.properties.hibernate.create_empty_composites.enabled=true isn't working. I'm not sure if Spring just doesn't recognize certain properties or if it's just the wrong place to put it.
What I'd like to know is if there is another way to edit the Hibernate properties directly or if there is another fix.

Analysis
The base assumption. More likely you are using Spring Boot 1.5.*.
Spring Boot 1.5.* uses Hibernate 5.0.*. GitHub proof.
Hibernate supports the hibernate.create_empty_composites.enabled setting since the 5.1 version.
GitHub proof.
JIRA proof (?): [HHH-7610] Option for injecting empty (non-null) embedded when all columns are NULL - Hibernate JIRA.
Release notes proof: ORM 5.1 feature release.
Solution
Please consider upgrading the Hibernate dependency in your pom.xml to a more recent version (5.1 and higher).
After that, it should work just fine:
In addition all properties in spring.jpa.properties.* are passed through as normal JPA properties (with the prefix stripped) when the local EntityManagerFactory is created.
— Spring Boot 1.5.* reference, 77. Data Access, 77.5 Configure JPA properties.

Related

Do spring-data-jpa annotations not work in webflux environment?

I am new to spring webflux and want to build my first application.
I am used to build my entities first and give them anntotations like javax.persitence.Entity, javax.persitence.OneToMany, ... and let spring generate my tables for me.
But...in all tutorials I found there is always only the #Table annotation used and there is no spring-boot-starter-jpa dependencies in the pom. Webflux does not even seem to work anymore if I add that dependency (Then there were no ReacticeCrudRepositories found anymore). All tables were created manually.
So using spring-boot-starter-jpa and its annotations seems to be forbidden.
But how do I model my entities, e.g. OneToMany and ManyToOne when I do not have my annotations anymore?
Is there no auto-generate option anymore?
Thank you very much

It is possible to change the name of the DATABASECHANGELOGLOCK table in Liquibase?

It is possible to change the name of the DATABASECHANGELOGLOCK table in Liquibase?
I hoped that it could be in a application.yml file, but I did not find such a property in the documentation:
https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
You can change the value of Liquibase's 'log lock' table name by passing a JVM system property named liquibase.databaseChangeLogLockTableName. For example:
-Dliquibase.databaseChangeLogLockTableName=MY_LOG_LOCK_TABLE_NAME
Spring Boot's integration with Liquibase does not support this property, so you cannot define this as a Spring property and have Spring Boot propagate it to Liquibase. The Liquibase properties which Spring Boot does suport are listed here but you have already spotted these. Until Spring Boot does support propagating this property I think you'll have to supply it via the command line.
FWIW, the Maven plugin for Liquibase does support this via the optional parameter: databaseChangeLogLockTableName. More details in the docs.

adding spring-data-rest ontop of spring-data-jpa

i created a maven project, and added all dependencies i need.
i have some repositories using the spring-data-jpa, and i added some integration tests.
now i need to add ontop of it spring-data-rest, if i understand it is based on springmvc.
but all examples i found, i need to add spring boot to start the app.
i noticed also all new spring projects use spring boot.
this means that i have to learn and use it for my projects?
how can i use spring-data-jpa+spring-data-jpa with an existing servlet3 project
The reason all examples are written using Boot is that Boot is indeed the way you should start a new Spring project these days. It free's from a lot of the tedious work of setting up the infrastructure, finding dependencies in the right version etc.
To use Spring Data REST without Boot, simply add the necessary dependencies to your project. The easiest way to do this is to use the Spring Data Release Train BOM (which will help you pulling in the correct matching versions) along side the version-less dependency declarations for Spring Data REST WebMVC and - in your case - Spring Data JPA.
Then go ahead and either register RepositoryRestMvcConvfiguration as Spring bean (either through XML configuration or JavaConfig).
All of this is also documented in the reference documentation.

How to use Flyway in Spring Boot with JDBC Security?

I would like to use Flyway as preferred way of database migration handling in my Spring Boot project (using current V1.2.1.RELEASE).
This is working fine so far however the integration with Spring Security using a JDBC DataSource seems to override the Flyway mechanism.
Following simple scenario:
Spring Boot 1.2.1
PostgreSQL 9.4.1
Flyway migration scripts for users, groups and authorities according to Spring Security documentation
Problem:
The Flyway migration scripts are not executed at startup as expected.
Maybe cause: It seems that Flyway is only executed at startup if the using Spring Boot project is also using JPA at least. Since Spring Security is based on plain JDBC, I've tried to temporary use the JDBC based database initialization scheme as described in Spring Boot docs (Chapter 68.3) which works, but (as documented) this way is like the 'poor man approach' and I'd really like to use Flyway also for these tables containing the User/Group/Authorities information.
Ok, after some further investigation I've found the problem:
Indeed, in a standard Spring Boot project the security context is initialized before any Flyway based migration takes place.
Normally this is not a big issue, but I've also used the AuthenticationManagerBuilder for creating a default admin user. This seems to be the wrong approach for creating such an initial user account.

spring persistence xml

What is the difference between:
persistenc.xml can be configured with hibernate properties OR Javax.persistence properties.
What scenarios would you use either one.
I tried using javax.persistence but my spring app would not work.. changed it to hibernate and it started working.
javax.persistence is the standard. Hibernate is an implementation. If you are completely sure that your DB layer will always be handled by Hibernate, go ahead and configure using Hibernate. If not, use javax.persistence, so that you could change your DB layer in the future.

Resources