0

The JPA do not translate @Column(name="...") inside sql statement The error log

[6418c947-1] There was an unexpected error (type=Internal Server Error, status=500).
PreparedStatementCallback; bad SQL grammar [SELECT mwo_main_status._id AS _id, mwo_main_status.oid AS oid, mwo_main_status.label AS label, mwo_main_status.details AS details FROM mwo_main_status]; nested exception is org.postgresql.util.PSQLException: ERROR: column mwo_main_status.oid does not exist Dica: Perhaps you meant to reference the column "mwo_main_status._id". Posição: 36

my ORM

@Builder
@Data
@Entity
@Table("mwo_sub_status")
public class WorkOrderSubStatusDbMapping {

    @GeneratedValue(strategy= GenerationType.IDENTITY)
    private @Id Integer _id;

    @Column(name="ref_id")
    private Integer oid;
    private String label;
    private String details;
}

I expected that the generated SQL to be:

SELECT mwo_main_status._id AS _id, mwo_main_status.ref_id AS oid, mwo_main_status.label AS label, mwo_main_status.details AS details FROM mwo_main_status

I'm creating a Spring-Boot Application with submodules (web, domain, persistence)
In Persistence module my gradle.build file is

apply plugin: 'java-library'

dependencies {
    implementation project(':domain')
    implementation 'io.projectreactor:reactor-core:3.3.3.RELEASE'
    implementation 'org.springframework:spring-context:5.2.4.RELEASE'

    implementation 'org.springframework:spring-orm:5.2.4.RELEASE'
    implementation 'org.springframework.data:spring-data-jdbc:1.1.5.RELEASE'

    implementation 'org.hibernate:hibernate-core:5.4.11.Final'
    runtimeOnly('org.postgresql:postgresql')

    runtimeOnly('org.postgresql:postgresql')

    testImplementation 'junit:junit:4.12'
}

What I'm missing?


As said in Using lomboks @Data and @Builder on entity, Lombok do not work proper with jdbc, so I decided to use spring-data-jpa instead of spring-data-jdbc.

Thanks Alex Rudenko.

1 Answers1

0

Possibly, it could be this

@Entity
@Table(name = "mwo_main_status")
public class WorkOrderSubStatusDbMapping {
    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    private Integer _id;

    @Column(name = "ref_id")
    private Integer oid;
    private String label;
    private String details;    
}
Nowhere Man
  • 19,170
  • 9
  • 17
  • 42
  • I forgot to copy the annotations, sorry about that. And is not the @Entity =/ – Janaina Scal Apr 10 '20 at 21:45
  • Mixing lombok's annotations with JPA @Entity is not recommended, perhaps you need to update them as suggested here: https://stackoverflow.com/questions/40516058/using-lomboks-data-and-builder-on-entity – Nowhere Man Apr 11 '20 at 21:02