Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass additional parameters to MariaDB connect string to fix timezone issue (e.g. useLegacyDatetimeCode)

I'm deploying some spring-boot app to Swisscom AppCloud which uses a MariaDB service. The service gets automatically configured in my app using the CloudFoundry connectors and the connection works fine.

However: since I heavily use ZonedDateTime-Objects in my Java-Code, I also included in the pom.xml...

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-java8</artifactId>
    </dependency>

...to properly preserve the ZonedDateTimes in the database.

This works fine on my local MariaDB, when I add...

    ...?useLegacyDatetimeCode=false

...to the connect string (as described here: https://moelholm.com/2016/11/09/spring-boot-controlling-timezones-with-hibernate/ -> "BONUS TIP: Getting the Hibernate configuration to work with MariaDB / MySQL").

How can I add this flag (and maybe others, too) to the connection to the MariaDB service on Swisscom AppCloud?

like image 948
Lost Carrier Avatar asked Dec 12 '25 13:12

Lost Carrier


1 Answers

If you use Spring on CloudFoundry in conjunction with a MariaDB binding, the datasource is automatically configured by this mechanism: https://docs.cloudfoundry.org/buildpacks/java/spring-service-bindings.html

This is powered by the Spring cloud connectors project, which you can customize to your needs.

I did not test it, but you should be able to set the driver properties as follows:

@Bean
public DataSource dataSource() {
    PoolConfig poolConfig = new PoolConfig(5, 30, 3000);
    ConnectionConfig connConfig = new ConnectionConfig("useLegacyDatetimeCode=false");
    DataSourceConfig dbConfig = new DataSourceConfig(poolConfig, connConfig);
    return connectionFactory().dataSource(dbConfig);
}
like image 182
Matthias Winzeler Avatar answered Dec 15 '25 05:12

Matthias Winzeler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!