SpringBoot JPA creating wrong JPQL and throwing org.hibernate.exception.SQLGrammarException

My entities has OneToMany relation. Below is the code:

Entity Classes :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>@Data
@Entity
@Table(name = "TEST_LADDER", schema = "TEST_DBO")
public class LadderEntityTemp implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.UUID)
@Column(name = "LADDER_SEQUENCE_ID", nullable = false, insertable = true)
protected UUID ladderSequenceId;
@Column(name = "LADDER_ID")
protected String ladderId;
@Column(name = "LADDER_ACCOUNT_NBR")
protected String ladderAccountNbr;
and more.....
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "ladderEntityTemp")
private List<RungEntityTemp> ladderRungs;
}
@Data
@Entity
@Table(name = "TEST_LADDER_RUNG", schema = "TEST_DBO")
public class RungEntityTemp implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.UUID)
@Column(name = "LADDER_RUNG_SEQUENCE_ID", nullable = false, insertable = true, table = "")
private UUID ladderRungSequenceId;
@Column(name = "LADDER_SEQUENCE_ID")
protected UUID ladderSequenceId;
@Column(name = "LADDER_RUNG_NBR")
protected Integer ladderRungNbr;
and more.....
@ManyToOne(fetch = FetchType.LAZY, optional = false)
private LadderEntityTemp ladderEntityTemp;
}
</code>
<code>@Data @Entity @Table(name = "TEST_LADDER", schema = "TEST_DBO") public class LadderEntityTemp implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.UUID) @Column(name = "LADDER_SEQUENCE_ID", nullable = false, insertable = true) protected UUID ladderSequenceId; @Column(name = "LADDER_ID") protected String ladderId; @Column(name = "LADDER_ACCOUNT_NBR") protected String ladderAccountNbr; and more..... @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "ladderEntityTemp") private List<RungEntityTemp> ladderRungs; } @Data @Entity @Table(name = "TEST_LADDER_RUNG", schema = "TEST_DBO") public class RungEntityTemp implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.UUID) @Column(name = "LADDER_RUNG_SEQUENCE_ID", nullable = false, insertable = true, table = "") private UUID ladderRungSequenceId; @Column(name = "LADDER_SEQUENCE_ID") protected UUID ladderSequenceId; @Column(name = "LADDER_RUNG_NBR") protected Integer ladderRungNbr; and more..... @ManyToOne(fetch = FetchType.LAZY, optional = false) private LadderEntityTemp ladderEntityTemp; } </code>
@Data
@Entity
@Table(name = "TEST_LADDER", schema = "TEST_DBO")
public class LadderEntityTemp implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.UUID)
    @Column(name = "LADDER_SEQUENCE_ID", nullable = false, insertable = true)
    protected UUID ladderSequenceId;
    @Column(name = "LADDER_ID")
    protected String ladderId;
    @Column(name = "LADDER_ACCOUNT_NBR")
    protected String ladderAccountNbr;
    and more.....

    @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "ladderEntityTemp")
    private List<RungEntityTemp> ladderRungs;
}

@Data
@Entity
@Table(name = "TEST_LADDER_RUNG", schema = "TEST_DBO")
public class RungEntityTemp implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.UUID)
    @Column(name = "LADDER_RUNG_SEQUENCE_ID", nullable = false, insertable = true, table = "")
    private UUID ladderRungSequenceId;
    @Column(name = "LADDER_SEQUENCE_ID")
    protected UUID ladderSequenceId;
    @Column(name = "LADDER_RUNG_NBR")
    protected Integer ladderRungNbr;
    and more.....

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private LadderEntityTemp ladderEntityTemp;
}

Repository Class :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>@Repository
public interface LaddersRepositoryTemp extends JpaRepository<LadderEntityTemp, UUID> {
@Query(value = "SELECT * from TEST_DBO.TEST_LADDER ld where ld.LADDER_ACCOUNT_NBR = :accountNum", nativeQuery = true)
List<LadderEntityTemp> tempQuery(String accountNum);
}
</code>
<code>@Repository public interface LaddersRepositoryTemp extends JpaRepository<LadderEntityTemp, UUID> { @Query(value = "SELECT * from TEST_DBO.TEST_LADDER ld where ld.LADDER_ACCOUNT_NBR = :accountNum", nativeQuery = true) List<LadderEntityTemp> tempQuery(String accountNum); } </code>
@Repository
public interface LaddersRepositoryTemp extends JpaRepository<LadderEntityTemp, UUID> {
    @Query(value = "SELECT * from TEST_DBO.TEST_LADDER ld where ld.LADDER_ACCOUNT_NBR = :accountNum", nativeQuery = true)
    List<LadderEntityTemp> tempQuery(String accountNum);
}

DBConfigClass :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = "com.temp.repositories",
entityManagerFactoryRef = "entityManagerFactory",
transactionManagerRef= "transactionManager")
public class DatabaseConfig {
private static final String BASE_PACKAGE = "com.temp.model.entities";
@Primary
@Bean(name = "tempDatasource")
@ConfigurationProperties(prefix = "temp.datasource")
public DataSource tempDataSource() {
return DataSourceBuilder.create().build();
}
@Primary
@Bean(name = "entityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
EntityManagerFactoryBuilder builder, @Qualifier("tempDatasource") DataSource tempDatasource) {
Map<String,Object> properties = new HashMap<>();
properties.put("hibernate.hbm2ddl.auto", "none");
properties.put("hibernate.dialect", "org.hibernate.dialect.Oracle12cDialect");
properties.put("oracle.net.encryption_client", "REQUIRED");
properties.put("oracle.net.encryption_types_client", "( AES256 )");
return builder.dataSource(tempDatasource).packages(BASE_PACKAGE).properties(properties).build();
}
@Primary
@Bean(name = "transactionManager")
public PlatformTransactionManager transactionManager(
@Qualifier("entityManagerFactory") EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
}
}
</code>
<code>@Configuration @EnableTransactionManagement @EnableJpaRepositories(basePackages = "com.temp.repositories", entityManagerFactoryRef = "entityManagerFactory", transactionManagerRef= "transactionManager") public class DatabaseConfig { private static final String BASE_PACKAGE = "com.temp.model.entities"; @Primary @Bean(name = "tempDatasource") @ConfigurationProperties(prefix = "temp.datasource") public DataSource tempDataSource() { return DataSourceBuilder.create().build(); } @Primary @Bean(name = "entityManagerFactory") public LocalContainerEntityManagerFactoryBean entityManagerFactory( EntityManagerFactoryBuilder builder, @Qualifier("tempDatasource") DataSource tempDatasource) { Map<String,Object> properties = new HashMap<>(); properties.put("hibernate.hbm2ddl.auto", "none"); properties.put("hibernate.dialect", "org.hibernate.dialect.Oracle12cDialect"); properties.put("oracle.net.encryption_client", "REQUIRED"); properties.put("oracle.net.encryption_types_client", "( AES256 )"); return builder.dataSource(tempDatasource).packages(BASE_PACKAGE).properties(properties).build(); } @Primary @Bean(name = "transactionManager") public PlatformTransactionManager transactionManager( @Qualifier("entityManagerFactory") EntityManagerFactory entityManagerFactory) { return new JpaTransactionManager(entityManagerFactory); } } </code>
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = "com.temp.repositories",
        entityManagerFactoryRef = "entityManagerFactory",
        transactionManagerRef= "transactionManager")
public class DatabaseConfig {
    private static final String BASE_PACKAGE = "com.temp.model.entities";

    @Primary
    @Bean(name = "tempDatasource")
    @ConfigurationProperties(prefix = "temp.datasource")
    public DataSource tempDataSource()  {
        return DataSourceBuilder.create().build();
    }

    @Primary
    @Bean(name = "entityManagerFactory")
    public LocalContainerEntityManagerFactoryBean entityManagerFactory(
            EntityManagerFactoryBuilder builder, @Qualifier("tempDatasource") DataSource tempDatasource) {
        Map<String,Object> properties = new HashMap<>();
        properties.put("hibernate.hbm2ddl.auto", "none");
        properties.put("hibernate.dialect", "org.hibernate.dialect.Oracle12cDialect");
        properties.put("oracle.net.encryption_client", "REQUIRED");
        properties.put("oracle.net.encryption_types_client", "( AES256 )");
        return builder.dataSource(tempDatasource).packages(BASE_PACKAGE).properties(properties).build();
    }

    @Primary
    @Bean(name = "transactionManager")
    public PlatformTransactionManager transactionManager(
            @Qualifier("entityManagerFactory") EntityManagerFactory entityManagerFactory) {
        return new JpaTransactionManager(entityManagerFactory);
    }
}

pom.xml code snippet for jpa :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.8</version>
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
</code>
<code> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.0.8</version> </parent> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> </code>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.0.8</version>
  </parent>
  <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
  </dependency>

When calling
List<LadderEntityTemp> ladderEntityList = laddersRepository.tempQuery(accountNumber); I find in the log that JPA trying to execute below 2 queries:

Custom Query – Hibernate: SELECT * from TEST_DBO.TEST_LADDER ld where ld.LADDER_ACCOUNT_NBR = ?

A JPQL – Hibernate: select l1_0.ladderEntityTemp_LADDER_SEQUENCE_ID,l1_0.LADDER_RUNG_SEQUENCE_ID,l1_0.LADDER_RUNG_NBR,l1_0.LADDER_SEQUENCE_ID from TEST_DBO.TEST_LADDER_RUNG l1_0 where l1_0.ladderEntityTemp_LADDER_SEQUENCE_ID=?

and Getting below errors :

WARN org.hibernate.engine.jdbc.spi.SqlExceptionHelper 133 : Local-1 : SQL Error: 904, SQLState: 42000
ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper 138 : Local-1 : ORA-00904: “L1_0″.”LADDERENTITYTEMP_LADDER_SEQUENCE_ID”: invalid identifier

2024-04-25 12:10:35 ERROR com.temp.controller.LadderController 120 : Local-1 : Ladder API Error : Exception in search inventory and save model ladder request:
org.hibernate.exception.SQLGrammarException: JDBC exception executing SQL [select l1_0.ladderEntityTemp_LADDER_SEQUENCE_ID,l1_0.LADDER_RUNG_SEQUENCE_ID,l1_0.LADDER_RUNG_NBR,l1_0.LADDER_SEQUENCE_ID from TEST_DBO.FIXED_INCOME_LADDER_RUNG l1_0 where l1_0.ladderEntityTemp_LADDER_SEQUENCE_ID=?]
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:64)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:56)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95)

I have tried couple of options after googleing on this issue by adding below properties to stop atleast the error:

spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.DefaultNamingStrategy

spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl

spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

but nothing worked.

Questions :

  1. What wrong i did in the code?
  2. Why JPA JPQL creating wrong column name “LADDERENTITYTEMP_LADDER_SEQUENCE_ID”?
  3. How can i stop JPA to execute the second auto generated JPQL because i don’t need that data while executing the custom query.
  4. Is that problem with the version of JPA? I am using spring-boot-starter-parent: “3.0.8” which seems has dependency on jakarta.persistence-api: “3.0.1”.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật