When I use findAll() method, there is error.
- 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
- 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
- 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.
- repository
public interface MyTableRepository extends JpaRepository<MyTableEntity,Long>{
}
Repository has no method.
- 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().
- 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?