0
respostas

Dúvida Curso Spring-Boot

Hola.

Fiz o curso de Spring e estou montando um projeto meu para fortalecer o conhecimento e peguei um modelo de um banco para implementar os conhecimentos do Sping-Boot.

Fiz os modelos das classes e coloquei as dependencias do H2 e JPA, porem ao criar o arquivo data.sql estou tendo um problema que vou mostrar abaixo:

Modelo do User

@Entity(name = "users")
public class User {

    @Id
    @GeneratedValue(strategy = IDENTITY)
    private Long id;
    private String firstName;
    @OneToMany(mappedBy="user")
    private List<PaymentMethod> paymentMethods;
    private Double maxWithdrawalAmount;
}

Modelo do PaymentMethod

@Entity(name = "payment_methods")
public class PaymentMethod {

    @Id
    @GeneratedValue(strategy = IDENTITY)
    private Long id;
    @ManyToOne
    @JsonIgnore
    private User user;
    private String name;

}

Arquivo para popular o banco H2:

INSERT INTO users VALUES (1, 'David', 100, 4);
INSERT INTO users VALUES (2, 'Arnold', 200, 2);
INSERT INTO users VALUES (3, 'Ilona', 150, 3);

INSERT INTO payment_methods (user_id, name) VALUES (1, 'My bank account');
INSERT INTO payment_methods (user_id, name) VALUES (1, 'My mom account');
INSERT INTO payment_methods (user_id, name) VALUES (2, 'Work account');
INSERT INTO payment_methods (user_id, name) VALUES (3, 'My bank account');
INSERT INTO payment_methods (user_id, name) VALUES (3, 'Secret account');

Agora quando quero subir a app me salta esse erro:

Caused by: org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/C:/Users/gabri/git/alura-mybank/target/classes/data.sql]: INSERT INTO users VALUES (1, 'David', 1, 100); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Column count does not match; SQL statement:
INSERT INTO users VALUES (1, 'David', 1, 100) [21002-200]

Eu vi no console do H2 que a tabela user nao criou o valor paymentMethod:

SELECT * FROM USERS;
ID      FIRST_NAME      MAX_WITHDRAWAL_AMOUNT  
(no rows, 2 ms)

Falta alguma coisa no modelo do Usuario?