Skip to content

Instantly share code, notes, and snippets.

@c0ldd
Last active June 21, 2025 00:33
Show Gist options
  • Save c0ldd/2e1263598171d82b31040e752185f16d to your computer and use it in GitHub Desktop.
Save c0ldd/2e1263598171d82b31040e752185f16d to your computer and use it in GitHub Desktop.
querydsl-sql with H2 tables generated from liquibase scripts
// configured plugins in pom.xml
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<defaultSchemaName>MYSCHEMA</defaultSchemaName>
<changeLogFile>src/main/resources/db/master.changelog.xml</changeLogFile>
<url>jdbc:h2:./target/tl_tables;AUTO_SERVER=TRUE;MV_STORE=FALSE;MVCC=FALSE;INIT=create schema IF NOT EXISTS MYSCHEMA</url>
<driver>org.h2.Driver</driver>
</configuration>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-maven-plugin</artifactId>
<version>3.7.4</version>
<executions>
<execution>
<goals>
<goal>export</goal>
</goals>
</execution>
</executions>
<configuration>
<jdbcDriver>org.h2.Driver</jdbcDriver>
<jdbcUrl>jdbc:h2:${project.basedir}/target/tl_tables;AUTO_SERVER=TRUE</jdbcUrl>
<packageName>my.test.db</packageName>
<tableNamePattern>TABELE1,TABLE2<!--your tables here--></tableNamePattern>
<targetFolder>${project.basedir}/target/generated-sources/java</targetFolder>
</configuration>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.196</version>
</dependency>
</dependencies>
</plugin>
@ilankumarani
Copy link

ilankumarani commented Jun 21, 2025

Impressive idea and I followed the same but it does not work with latest Spring boot, so I have changed a bit.

<plugin>
    <groupId>org.liquibase</groupId>
    <artifactId>liquibase-maven-plugin</artifactId>
    <version>4.31.1</version>

    <executions>
        <execution>
            <id>table-from-liquibase</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>update</goal>
            </goals>
            <configuration>
                <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
                <defaultSchemaName>h2</defaultSchemaName>
                <changeLogFile>src/main/resources/db.changelog/changelog.yml</changeLogFile>
                <url>jdbc:h2:${project.build.directory}/h2/tl_tables;INIT=create schema IF NOT EXISTS MYSCHEMA;</url>
                <username>sa</username>  <!-- Directly specify the username -->
                <password>password</password>  <!--  Consider using a more secure method for password -->
            </configuration>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>2.3.232</version>
        </dependency>
    </dependencies>
</plugin>


<plugin>
<groupId>io.github.openfeign.querydsl</groupId>
<artifactId>querydsl-maven-plugin</artifactId>
<version>7.0</version>

<executions>
    <execution>
        <configuration>
            <jdbcDriver>org.h2.Driver</jdbcDriver>
            <jdbcUrl>jdbc:h2:${project.build.directory}/h2/tl_tables;</jdbcUrl>
            <jdbcUser>sa</jdbcUser>
            <jdbcPassword>password</jdbcPassword>
            <packageName>com.ilan.query.sql</packageName>
            <targetFolder>${project.basedir}/target/generated-sources/java</targetFolder>
            <namePrefix>S</namePrefix>
            <schemaToPackage>true</schemaToPackage>
            <exportAll>false</exportAll>
            <exportTables>true</exportTables>
            <exportBeans>true</exportBeans>
            <beanAddFullConstructor>true</beanAddFullConstructor>
            <beanAddToString>true</beanAddToString>
            <beanPrefix>P</beanPrefix>
            <beanPrintSupertype>true</beanPrintSupertype>
        </configuration>
        <id>querydsl-sql-from-liquibase</id>
        <phase>generate-sources</phase>
        <goals>
            <goal>export</goal>
        </goals>
    </execution>
</executions>

<dependencies>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>2.3.232</version>
    </dependency>
</dependencies>
</plugin>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy