Setting Hibernate Dialect not working with Spring and YML config - spring

this is my config:
spring.jpa:
hibernate:
ddl-auto: update
connection:
charset: utf8
useUnicode: true
properties.hibernate.dialect: org.hibernate.dialect.MySQL5InnoDBDialect
Based on what I found in docs and SO it should work but still new tables are create with MyISAM instead of InnoDB.
What is wrong in my config?

The property for setting the dialect is actually spring.jpa.properties.hibernate.dialect
Try this:
spring.jpa:
hibernate:
connection:
charset: utf8
useUnicode: true
ddl-auto: update
properties.hibernate.dialect: org.hibernate.dialect.MySQL5InnoDBDialect
Spring boot sample for reference

Provide below change in your application.yml
spring.datasource:
url: jdbc:mysql://?verifyServerCertificate=false&useSSL=true&requireSSL=false
username:
password:
spring.jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.MySQLDialect
It will work :)

Related

Migrate H2 database 1.4.200 > 2.1.214 in my Spring Batch Application

For security purpose I have to migrate my H2 library from 1.4.200 to 2.1.214 in my Spring Batch application
In 1.4.200 version, all my Junit test are OK but with new version, start of the application failed :
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "BATCH_JOB_INSTANCE" not found (this database is empty); SQL statement:
SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ? and JOB_KEY = ? [42104-214]
I have juste change H2 version in my pom.xml
Spring Batch application use Spring Boot 2.1.11.RELEASE dependencies.
Do you know why this tables aren't find ?
spring:
application:
name: myBatch
cache:
type: simple
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:h2:mem:myBatch;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
name:
username:
password:
hikari:
auto-commit: false

Failed to determine suitable jdbc url when deploy on gitlab

When I run the application locally, it works.
When I deploy the master branch in gitlabs's CI/CD pipeline it works too.
But when I run the deploy to other branch it launch an error:
APPLICATION FAILED TO START
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine suitable jdbc url
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (the profiles stag are currently active).
My application.yml:
datasource:
driver-class-name: org.postgresql.Driver
url: ${POSTGRES_URL}
username: ${POSTGRES_USER}
password: ${POSTGRES_PASS}
hikari:
connectionTimeout: 20000
idleTimeout: 20000
maxLifetime: 60000
maximum-pool-size: 10
jpa:
hibernate:
show-sql: true
ddl-auto: validate
properties:
hibernate:
globally_quoted_identifiers: true
dialect: org.hibernate.dialect.PostgreSQL10Dialect
show_sql: true
format_sql: true
database-platform: org.hibernate.dialect.PostgreSQL10Dialect

how to rotate log file in spring boot

I tried to create a log file configuration that creates a new log file when it sized by 20MB. I'm using the application.yaml file . I've searched for this file configuration in docs and in the internet but didn't work im my machine. I also tried another approaches like the location of the file , the delimiters ( change by / ) , and the hierarchy of the properties in the application.yaml.
so my file configuration its like :
server:
port: 8080
logging.file: D:\logs\logfile.txt
logging:
file:
max-history: 20
max-size: 50MB
level:
org.springframework.web: DEBUG
org.hibernate: DEBUG
spring:
mvc:
throw-exception-if-no-handler-found: true
resources:
add-mappings: false
security:
basic:
enable: false
server:
contextPath: /
datasource:
url: jdbc:postgresql://servername.myent.com:5432/appname
username: meandmsjake
password: 123abc
driver-class-name: org.postgresql.Driver
type: com.zaxxer.hikari.HikariDataSource
hikari:
maximum-pool-size: 20
idle-timeout: 10000
jpa:
#database-platform: org.hibernate.dialect.PostgreSQLDialect
database-platform: org.hibernate.spatial.dialect.postgis.PostgisDialect
show-sql: true
properties:
hibernate:
temp:
use_jdbc_metadata_defaults: false
hibernate:
ddl-auto: none
There appear to be two issues here:
I'm not sure that setting both logging.file and logging.file.max-history will work in yaml, considering the tree structure. To remedy this, I would try to put these particular properties in the yaml.
I don't believe that server.logging.file is the correct property (as you have it here). It should be simply logging.file. Accordingly, the other properties should not be prefixed with "server".
That said, it would be helpful if you posted the version of Spring Boot that you are using.

Problem with port determination using spring cloud

I have created 2 instances of a microservice named InfyGo_Flights. I have put a yaml file in git hub with
server.port 9004. My properties file in MS is empty apart from application name. These 2 instances have 2 diff issues:
1.First I overrode in the config itself to take server.port as 9010. But still ran on 9004. I deleted the server.port in yaml in github. But this caused it to run into error. So replaced it with 9004 again. But now it has started running on 9010. Removing the overridden property causes it to run into error.
2.Second config I created after the first one was causing issue. But despite the yaml file in cloud config it runs on default 8080 port.
application.properties:
spring.application.name=InfyGo_Flights
bootstrap.properties
spring.cloud.config.uri=http://localhost:1111
management.endpoints.web.exposure.include
InfyGo_Flights.yml
spring:
application:
name: InfyGo_Flights
mvc:
view:
prefix: /WEB-INF/pages/
suffix: .jsp
datasource:
username: root
password:
url: jdbc:mysql://localhost:3307/mydb?serverTimezone=UTC
jpa:
show-sql: true
hibernate:
ddl-auto: update
properties:
hibernate:
dialect:
logging:
file: Errorlog.log
level:
root: info
com.infoys.ars: info
pattern:
file: "%d{yyyy-MM-dd HH:mm:ss,SSS} %5p [%t] %c [%M] - %m%n"
server:
port:9004
You will need to put a Whitespace between the port & 9004 so it get recognizable by the yaml file:
//wrong
port:9004
//right
port: 9004

Configuring application using application.yaml instead of application.properties

I have a small Quarkus 1.1.0.Final Web application (using Java 1.8). I'm trying to use a YAML file to configure the application (instead of the usual application.properties) but there is no way the application comes up. I'm always getting this not-so-useful error message(s):
13:53:32,494 ERROR [io.qua.dev.DevModeMain] Failed to start Quarkus: java.lang.RuntimeException: io.quarkus.builder.ChainBuildException: No producers for required item class io.quarkus.deployment.builditem.BuildTimeRunTimeFixedConfigurationBuildItem
at io.quarkus.runner.RuntimeRunner.run(RuntimeRunner.java:180)
at io.quarkus.dev.DevModeMain.doStart(DevModeMain.java:177)
at io.quarkus.dev.DevModeMain.start(DevModeMain.java:95)
at io.quarkus.dev.DevModeMain.main(DevModeMain.java:66)
Caused by: io.quarkus.builder.ChainBuildException: No producers for required item class io.quarkus.deployment.builditem.BuildTimeRunTimeFixedConfigurationBuildItem
at io.quarkus.builder.BuildChainBuilder.build(BuildChainBuilder.java:240)
at io.quarkus.deployment.QuarkusAugmentor.run(QuarkusAugmentor.java:112)
at io.quarkus.runner.RuntimeRunner.run(RuntimeRunner.java:113)
... 3 more
13:53:32,519 INFO [io.qua.dev.DevModeMain] Attempting to start hot replacement endpoint to recover from previous Quarkus startup failure
13:53:32,532 ERROR [io.qua.dev.DevModeMain] Failed to start quarkus: java.lang.IllegalArgumentException: workerPoolSize must be > 0
at io.vertx.core.VertxOptions.setWorkerPoolSize(VertxOptions.java:275)
at io.quarkus.vertx.core.runtime.VertxCoreRecorder.convertToVertxOptions(VertxCoreRecorder.java:151)
at io.quarkus.vertx.core.runtime.VertxCoreRecorder.initializeWeb(VertxCoreRecorder.java:104)
at io.quarkus.vertx.http.runtime.VertxHttpRecorder.startServerAfterFailedStart(VertxHttpRecorder.java:115)
at io.quarkus.vertx.http.deployment.devmode.VertxHotReplacementSetup.handleFailedInitialStart(VertxHotReplacementSetup.java:30)
at io.quarkus.dev.RuntimeUpdatesProcessor.startupFailed(RuntimeUpdatesProcessor.java:449)
at io.quarkus.dev.DevModeMain.doStart(DevModeMain.java:191)
at io.quarkus.dev.DevModeMain.start(DevModeMain.java:95)
at io.quarkus.dev.DevModeMain.main(DevModeMain.java:66)
This is my YAML file:
#
# https://quarkus.io/guides/all-config
# https://quarkus.io/guides/config#overriding-properties-at-runtime
quarkus:
datasource:
driver: org.postgresql.Driver
flyway:
migrate-at-start: true
health:
extensions:
enabled: true
hibernate-orm:
dialect: org.hibernate.dialect.PostgreSQL10Dialect
http:
port: 8080
log: # ALL > FINEST > FINER > FINE > CONFIG > INFO > WARNING > SEVERE > OFF
console:
async: true
color: true
enable: true
format: "%d{yyyy-MM-dd HH:mm:ss,SSS} |- %-5p in %c:%L{3.} [%t] - %s%e%n"
level: WARNING
resteasy:
path: /api
smallrye-openapi:
path: /open-api
swagger-ui:
always-include: true
path: /swagger-ui
"%dev":
quarkus:
datasource:
password: postgres
url: jdbc:postgresql://localhost:5432/quarkus_web
username: postgres
flyway:
clean-at-start: true
hibernate-orm:
log:
sql: true
statistics: true
log:
category:
"io.quarkus.arc.processor":
level: OFF
"io.quarkus":
level: INFO
"org.acme":
level: CONFIG
"%prod":
quarkus:
datasource:
password: postgres
url: jdbc:postgresql://localhost:5432/quarkus_web
username: postgres
flyway:
clean-at-start: false
hibernate-orm:
database:
generation: none
sql-load-script: no-file
"%test":
quarkus:
datasource:
password: postgres
url: jdbc:postgresql://localhost:5432/quarkus_web
username: postgres
flyway:
clean-at-start: true
log:
category:
"io.quarkus":
level: WARNING
"org.acme":
level: WARNING
Anyone using this approach already and succeeded? I'm including io.quarkus:quarkus-config-yaml:1.1.0.Final.
One thing that I've noticed is that I can't separate the profiles using --- as I do with Spring Boot. I think I should file an issue for this :thinking_face:
It certainly looks like a bug, maybe even 2 as the second error message doesn't look like something I would expect considering your configuration file.
Could you create a bug in our tracker: https://github.com/quarkusio/quarkus/issues/new?assignees=&labels=bug&template=bug_report.md&title= ?
It would be nice if you could provide a reproducer. AFAICS, Quarkus doesn't start at all so probably your pom.xml with the various extensions you use and your configuration file should be enough to reproduce the issue.
Turns out this was not an issue. I just had an old Gradle config; some things changed with the Gradle plugin with version 1.1.0.Final and I just didn't have those.

Resources