0

JPA repository throwing Error for custom query method:

org.h2.jdbc.JdbcSQLException: Table "NBMRBANKDTLSENTITY" not found; SQL statement:
select NBMRBankDtlsEntity from NBMRBankDtlsEntity  where NBMRBankDtlsEntity.ipphId = ? [42102-191]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)

Class :

@Repository
public interface NBMRBankDtlsRepository extends JpaRepository<NBMRBankDtlsEntity, Long> {

    @Query(value ="select n from NBMRBankDtlsEntity n  where n.ipphId = :ipphId",nativeQuery = true)
    Optional<NBMRBankDtlsEntity> findByIPPHId(@Param("ipphId") Long ipphId);

}
Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
sanju
  • 11
  • 6

2 Answers2

0

The error message tells you: Table "NBMRBANKDTLSENTITY" not found. Therefore it probably doesn't exist. To fix this you'll have to create the table, manually through a script or through hibernates schema creation feature.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
0

I am already creating a table also inserting the record, After that only i am calling this custom query method.

I have found the issue as i am using nativeQuery = true so it is expecting normal sql query to query DB directly not the java query which is creating issue. Now after changing below it works fine ,

@Query(value = "SELECT * from NB_MR_BANK_DTLS WHERE IPPH_ID = :ipphId",nativeQuery = true)

For java query we can use directly as it internally converts to SQL while querying the DB,

@Query(value = "select p from NBMRBankDtlsEntity p WHERE p.ipphId = :ipphId")

sanju
  • 11
  • 6