Set hibernate.id.new_generator_mappings in application.yaml - spring

I am trying to set the hibernate.id.new_generator_mappings property in order to use SequenceStyleGenerator, as I'm getting deprecation warnings for SequenceHiLoGenerator after upgrading to Spring Boot 1.4.0.RELEASE.
I tried adding the following entry to application.yaml but it has no effect:
spring:
jpa:
hibernate:
id:
new_generator_mappings: true
I also tried converting to application.properties file:
spring.jpa.hibernate.id.new_generator_mappings=true
Stepping through the JpaProperties class I can see where it's trying to parse the hibernate.id.new_generator_mappings property, but it is missing.
Is this a bug in Spring Boot, or do I have something configured incorrectly?

The correct setting, per the upgrade guide is:
spring.jpa.hibernate.use-new-id-generator-mappings

Related

H2: globally_quoted_identifiers seems not be taken into account

I use spring-boot 2.7.6 and H2 2.1.214.
To fix an issue due to the name of some columns that are also keywords in liquibase files (loaded to initialize the H2 database for tests) and entities, I tried to use the globally_quoted_identifiers property as defined here: https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#_quoting_options
So I did it like this:
spring:
jpa:
properties:
hibernate:
globally_quoted_identifiers: true
But I still have the same errors due to keywords (org.h2.jdbc.JdbcSQLSyntaxErrorException) so I do not know if I use it correctly?
As a workaround I have to use NON_KEYWORDS=VALUE,KEY but I would like to manage all keywords globally.

Disable spring property in app.yml is not possible

After Upgrading Spring-boot version, we are having circular depenencies problems. So
I want to see this with the current version of Spring-boot 2.2.13.RELEASE
So I added the following config to my application.yml.
spring.main.allow-circular-references = false
The problem is that it gives me an "Unknown property 'spring.main.allow-circular-references'"?
Is it Normal?
Kind regards,
If you are in a YML, the "normal" way to declare this property is like this:
spring:
main:
allow-circular-references: true
The default value since the last Spring version is false, so if you want to boot you need to start you need to set it to true (and fix it ;) )

Why is the placeholder not set properly in hikari.data-source-properties

I am setting the hikari.data-source-properties with a placeholder, but the placeholder value does not get substituted. It is a spring-boot 2.1.4.RELEASE based application. My intention is to set the Session properties so the DBAs can identify my application. Currently I get a default JDBC Thin Client for my connection when I run SELECT PROGRAM FROM V$SESSION from the DB
Below is what I have in my application.yml file
spring:
datasource:
url: "jdbc:oracle:thin:#machine:1521:service_name"
driver-class-name: "oracle.jdbc.driver.OracleDriver"
hikari.data-source-properties:
v$session.program:${spring.application.name}
Below is what I have in my bootstrap.yml file
spring:
application:
name: ms-db-service
When I query the Oracle DB, I notice that the value for program is literally ${spring.application.name}, instead of the expected value ms-db-service
I have tried the below, with same logical result:
Tried redefining the spring.application.name again in the application.yml
Tried using a different locally defined key ${name}
Added the following bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
Tried specifying the property as such: spring.datasource.hikari.data-source-properties: v$session.program=${spring.application.name}
I tried the below items to gain more knowledge of the situation:
I tried using a placeholder for spring.datasource.url and that worked fine
I tried to read the value manually using the below code, and that shows the correct values: #Value("${spring.datasource.hikari.data-source-properties}") String propVal;
My conclusion is that HikariCp reads these values before the placeholder substitution is done. I don't understand the relative timing of when the substitution and datasource bean creation happen in the spring-boot bean life-cycle
I am trying to avoid using a bean for hikaricp datasource (not sure if that will even solve the issue), as I don't want to manually build the whole datasource as hikari supports huge number of properties.
So, how can I set the spring.datasource.hikari.data-source-properties in application.yml using a placeholder. And, is there any other way to assign spring.application.name to identify my current db connection?
You have to use it like this:
spring:
datasource:
hikari:
data-source-properties:
"[v$session.program]": ${spring.application.name}

Spring Boot: failed to load JNDI variables into yml configuration file

According to Spring Boot documentation about Externalized configuration, I tried to load a JNDI variable into my yml configuration file, like this:
spring:
# Show or not log for each sql query
jpa:
show-sql: java:global/bc-api-immop/hibernate/show_sql
And it doesn't work.
I have my variable in my JNDI context:
I also tried this:
spring:
# Show or not log for each sql query
jpa:
show-sql
jndi-name: java:global/bc-api-immop/hibernate/show_sql
But, still the same result.
Do you have any idea what I'm doing wrong?
As weird as it sounds, I also have this code, and it works:
spring:
# Set here configurations for the database connection
datasource:
jndi-name: java:jboss/datasources/bc-appli-as400-ds
Edit: When I do this, it works to (so my issue really comes from getting my JNDI variable):
spring:
# Show or not log for each sql query
jpa:
show-sql: true
The way you have written your yaml is the real problem here
The general concept is key: value so by writing show-sql spring boot expects a value of true or false as it appears on Appendix A. Common application properties so it is normal that your property configuration fails and I am pretty sure that this is showing up somewhere in your log files.
On the first example when you write show-sql: java:global/bc-api-immop/hibernate/show_sql you are actually answering the question "Should I show you the generated SQL statements" with "Hi spring Boot this is your datasource" which we both understand it makes no sence to spring boot :)
Your last statement, on the other hand, is correct. You are defining under the yaml collection item datasource the property jndi-name: with value java:jboss/datasources/bc-appli-as400-ds
I would also suggest spending 10 minutes to read this article Learn X in Y minutes
So a correct approach would probably be
spring:
# Set here configurations for the database connection
datasource:
jndi-name: java:jboss/datasources/bc-appli-as400-ds
jpa:
show-sql: true
Let me know if I can help you more

Spring Boot and Eureka: eureka.client.healthcheck.enabled property not found

I have a Spring Boot Hystrix dashboard application where in a .property file I am trying to define some key/value pair(s) ― as per tutorial: https://exampledriven.wordpress.com/2016/07/05/spring-cloud-hystrix-example/
I am getting error when adding property eureka.client.healthcheck.enabled = true. The editor complains with:
Unknown property 'eureka.client.healthcheck'
Please, help me to find out the correct dependency, or if I am missing anything else.

Resources