Skip to content

ProjectTableCaseFormat and ProjectColumnCaseFormat does not work #107

Description

@vominhtrius

hi @lpandzic
I'm trying to use infobip-spring-data-querydsl with spring-data-jdbc module. I want to use the LOWER_UNDERSCORE naming convention for table and column names. I encountered a problem:

ProjectTableCaseFormat doesn't work

According to the Annotation processor document, I created a class with ProjectTableCaseFormat and ProjectColumnCaseFormat, but the naming convention is only applied to the column names on the Q class.

My config class

@ProjectTableCaseFormat(CaseFormat.LOWER_UNDERSCORE)
@ProjectColumnCaseFormat(CaseFormat.LOWER_UNDERSCORE)
public class QuerydslCaseFormatConfig {
}

Sample model class:

@Builder
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@ToString
@Table
public class Sample implements Serializable {
	@Id
	private Long id;

	private String name;

	private String description;

	private SampleStatus status;

	@CreatedDate
	private Instant createdAt;

	@LastModifiedDate
	private Instant updatedAt;
}

build.gradle

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.4.4'
    id 'io.spring.dependency-management' version '1.1.7'
}

group = 'com.test.demo'
version = '0.0.1-SNAPSHOT'

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(21)
    }
}

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    runtimeOnly 'com.mysql:mysql-connector-j'
    annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
    implementation 'com.infobip:infobip-spring-data-jdbc-querydsl-boot-starter:9.0.7'
    annotationProcessor 'com.infobip:infobip-spring-data-jdbc-annotation-processor:9.0.7'
}

tasks.named('test') {
    useJUnitPlatform()
}

QSample class:

/**
 * QSample is a Querydsl query type for Sample
 */
@Generated("com.infobip.spring.data.jdbc.annotation.processor.CustomMetaDataSerializer")
public class QSample extends com.querydsl.sql.RelationalPathBase<Sample> {

    private static final long serialVersionUID = 714346397;

    public static final QSample sample = new QSample("Sample");

    public final NumberPath<Long> id = createNumber("id", Long.class);

    public final StringPath name = createString("name");

    public final StringPath description = createString("description");

    public final EnumPath<SampleStatus> status = createEnum("status", SampleStatus.class);

    public final DateTimePath<java.time.Instant> createdAt = createDateTime("createdAt", java.time.Instant.class);

    public final DateTimePath<java.time.Instant> updatedAt = createDateTime("updatedAt", java.time.Instant.class);

    public QSample(String variable) {
        super(Sample.class, forVariable(variable), null, "");
        addMetadata();
    }

    public QSample(String variable, String schema, String table) {
        super(Sample.class, forVariable(variable), schema, table);
        addMetadata();
    }

    public QSample(String variable, String schema) {
        super(Sample.class, forVariable(variable), schema, "");
        addMetadata();
    }

    public QSample(Path<? extends Sample> path) {
        super(path.getType(), path.getMetadata(), null, "");
        addMetadata();
    }

    public QSample(PathMetadata metadata) {
        super(Sample.class, metadata, null, "");
        addMetadata();
    }

    public void addMetadata() {
        addMetadata(id, ColumnMetadata.named("id").withIndex(0));
        addMetadata(name, ColumnMetadata.named("name").withIndex(1));
        addMetadata(description, ColumnMetadata.named("description").withIndex(2));
        addMetadata(status, ColumnMetadata.named("status").withIndex(3));
        addMetadata(createdAt, ColumnMetadata.named("created_at").withIndex(4));
        addMetadata(updatedAt, ColumnMetadata.named("updated_at").withIndex(5));
    }

}

As we can see, the table name of QSample is empty, so it falls back to the default naming convention (Pascal casing).
I can solve this problem by adding the table name to @Table, but I don't want to use this method.
Am I misunderstanding or missing a step?

Thanks!

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions