0

When I use findAll() method, there is error.

  1. DB(mariadb)
use database myjpa;
CREATE TABLE table_name (
    pk INT PRIMARY KEY,
    value VARCHAR,
);
INSERT INTO mytable
VALUES (1,'hello111');
INSERT INTO mytable
VALUES (2,'hello222');

It is simple table. there is no error

  1. application.yml
spring:
  datasource:
    driver-class-name: org.mariadb.jdbc.Driver
    url: "jdbc:mariadb://localhost:3306/myjpa?autoReconnect=true&&useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&tinyInt1isBit=false"
    username: -
    password: -
    hikari:
      auto-commit: false
      connection-test-query: SELECT 1
      minimum-idle: 10
      maximum-pool-size: 20
      transaction-isolation: TRANSACTION_READ_UNCOMMITTED
      pool-name: pool-swtodo
  jpa:
    database-platform: org.hibernate.dialect.MariaDB103Dialect
    properties:
      hibernate:
        "[format_sql]": true
        "[hbm2ddl.auto]": update
        "[implicit_naming_strategy]": org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
        "[physical_naming_strategy]": org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
    open-in-view: false
    show-sql: true
  1. Entity
@Entity
@Getter
@Setter
@Table(name="mytable")
public class MyTableEntity {
    @Id
    private int pk;
    
    private String value;

    @Override
    public String toString(){
        return "pk"+" value";
    }
}

Entity is easy too, but i attach it.

  1. repository
public interface MyTableRepository extends JpaRepository<MyTableEntity,Long>{
}

Repository has no method.

  1. Test
@DataJpaTest
class MyjpaApplicationTests {

    @Autowired
    MyTableRepository myTableRepository;

    @Test
    @Rollback(true)
    void contextLoads() {
        List<MyTableEntity> allTable = myTableRepository.findAll();

        for (MyTableEntity myTableEntity : allTable) {
            System.out.println(myTableEntity);
        }
    }
}

Test Code is just printing mytable's all data. But there is error in myTableRepository.findAll().

  1. Error Msg
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "select mytableent0_.pk as pk1_0_, mytableent0_.[*]value as value2_0_ from mytable mytableent0_"; expected "identifier"; SQL statement:
select mytableent0_.pk as pk1_0_, mytableent0_.value as value2_0_ from mytable mytableent0_ [42001-214]

I cant find reason. Why there is error?

swz
  • 63
  • 6
  • `value` is a reserved word. See http://www.h2database.com/html/advanced.html#keywords – tgdavies Nov 22 '22 at 01:43
  • @gdavies Thanks to answer, but when I change value=>myvalue, it has same error. – swz Nov 22 '22 at 01:49
  • 1
    By the way, your config says you are using mariadb, but the error message says h2. – tgdavies Nov 22 '22 at 01:55
  • @tgdavies Thanks. There is h2 dependency. I thin h2 is kind of hibernate. There is error too, but I'll try again. Thanks. – swz Nov 22 '22 at 02:04
  • 1
    This error is caused by h2, not by mariaDB. If you add ```@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)``` to your Test class it will be fixed. – Umut Emre Önder Nov 22 '22 at 02:28
  • Oh, I have error, and I fix it. It's solution is your answer, amazing @UmutEmreÖnder Emre Önder – swz Nov 22 '22 at 02:42

0 Answers0