Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot JOOQ sql dialect not picked up from application.properties

Background: i am hosting the trial version of jooq 3.9.1 (proprietary eg oracle db compatible) in my nexus repository - all the dependencies in my pom relating to jooq point to that.

i have this line in my application.properties

jooq.sql-dialect=ORACLE

but when i inspect the injected dslContext the dialect is set to "DEFAULT" and not ORACLE as expected/desired.

I am currently getting round it by autowiring the datasource rather than the dslcontext and then setting the sql dialect (as shown below) - but wondering why autowiring the dslcontext directly doesnt work as expected

@Autowired
private DataSourceConnectionProvider dataSource;



public static final SQLDialect sqlDialect = SQLDialect.ORACLE;

public DSLContext getDSL(){
    return DSL.using(dataSource, sqlDialect);
}
like image 339
John Wilson Avatar asked Mar 29 '17 19:03

John Wilson


People also ask

Does Spring Boot support SQL dialects?

Since Spring Boot is able to recognize the SQL dialect in use through the existence of H2 artifact on the classpath, a dialect configuration is no longer necessary: 4. Using Spring Boot With jOOQ

Can we use jOOQ in Spring Boot?

30. Using jOOQ Java Object Oriented Querying ( jOOQ) is a popular product from Data Geekery which generates Java code from your database, and lets you build type safe SQL queries through its fluent API. Both the commercial and open source editions can be used with Spring Boot.

What is jOOQ Object Oriented Querying?

Overview This article will introduce Jooq Object Oriented Querying – Jooq – and a simple way to set it up in collaboration with the Spring Framework. Most Java applications have some sort of SQL persistence and access that layer with the help of higher-level tools such as JPA.

How to create a dslcontext Bean in Spring Boot?

A DSLContext bean is created in the same way as in the PersistenceContext class of the preceding tutorial: Lastly, a Configuration implementation needs to be provided to DSLContext. Since Spring Boot is able to recognize the SQL dialect in use through the existence of H2 artifact on the classpath, a dialect configuration is no longer necessary: 4.


2 Answers

Lukas' comment Spring Boot JOOQ sql dialect not picked up from application.properties is correct.

Here is an example how to do it and test:

Inside application.properties

spring.jooq.sql-dialect = Postgres

And tested with an integration test ConfigIT:

@RunWith(SpringRunner.class)
@JdbcTest
@ImportAutoConfiguration(JooqAutoConfiguration.class)
public class ConfigIT {

    @Autowired
    private DSLContext dSLContext;

    @Test
    public void dialectShouldBePickedUp() {
        assertThat(dSLContext.configuration().dialect(), is(SQLDialect.POSTGRES));
    }
}

You'll find the working and tested example in the repositories of http://springbootbuch.de here: https://github.com/springbootbuch/database_examples

What's important ist to choose the right, case sensitive name. In my example, it's Postgres, in your example it should be Oracle and you must use the right property. Sadly, those names vary across different tool sets. For jOOQ you'll find the constants in org.jooq.SQLDialect

like image 51
Michael Simons Avatar answered Oct 09 '22 00:10

Michael Simons


Spring Boot by default uses the org.jooq dependency, which is the Maven groupId for the jOOQ Open Source Edition:

<dependency>
    <groupId>org.jooq</groupId>
    <artifactId>jooq</artifactId>
</dependency>

However, the Oracle SQLDialect is contained only in the commercial distributions of jOOQ, which are available under different groupId (and not from Maven Central but from here (trial) and here (express, professional, enterprise edition)):

<groupId>org.jooq.pro</groupId>        <!-- for commercial editions -->
<groupId>org.jooq.pro-java-6</groupId> <!-- for commercial editions with Java 6 support -->
<groupId>org.jooq.trial</groupId>      <!-- for the free trial edition -->

The distributions are almost completely binary compatible, so you should be able to simply replace the <groupId> in your own pom.xml for Spring Boot to work with jOOQ and Oracle.

like image 39
Lukas Eder Avatar answered Oct 09 '22 01:10

Lukas Eder