Ryoma137 / record-of-expense

0 stars 0 forks source link

findAllテストに@sqlを付与 #1

Open Ryoma137 opened 2 years ago

Ryoma137 commented 2 years ago

下記の記事を参考に@sqlを付与。 すると、エラーが起きる。

エラーログ org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of class path resource [test-schema.sql]: INSERT INTO Amount(id, name, price,category,comments) VALUES(1,"Sandwich",450,"Food","What a scrumptious sandwich"); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Column "Sandwich" not found; SQL statement: INSERT INTO Amount(id, name, price,category,comments) VALUES(1,"Sandwich",450,"Food","What a scrumptious sandwich") [42122-212]

-- 参考記事 --

JUnit でテスト用のデータを使用する(@Sqlアノテーション ) https://qiita.com/daifuku_mochi2/items/075ec3f4be96e2c669d7

@sql https://spring.pleiades.io/spring-framework/docs/current/reference/html/testing.html#spring-testing-annotation-sql

Ryoma137 commented 2 years ago
Ryoma137 commented 2 years ago

VALUES内のvarcharの値が'ではなく"で囲われていたので、'に変更したことによって以下の問題は解決。 その後、エラーログ、No default constructor for entityが出たので、Amount.javaのコンストラクターをパラメータ有りのコンストラクターから、パラメータのないconstructorに変更するため、アノテーションを@AllArgsConstructorから@NoArgsConstructorに変更

下記の記事を参考に@Sqlを付与。 すると、エラーが起きる。

エラーログ org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of class path resource [test-schema.sql]: INSERT INTO Amount(id, name, price,category,comments) VALUES(1,"Sandwich",450,"Food","What a scrumptious sandwich"); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Column "Sandwich" not found; SQL statement: INSERT INTO Amount(id, name, price,category,comments) VALUES(1,"Sandwich",450,"Food","What a scrumptious sandwich") [42122-212]

-- 参考記事 --

JUnit でテスト用のデータを使用する(@Sqlアノテーション ) https://qiita.com/daifuku_mochi2/items/075ec3f4be96e2c669d7

@Sql https://spring.pleiades.io/spring-framework/docs/current/reference/html/testing.html#spring-testing-annotation-sql