0
respostas

JAVA SPRING - Load initial no arquivo sql falhando

Boa noite,

Tentei descobrir e li vários tópicos no google até agora não resolvi.

Entidade

@Data
@Entity
@Table(name = "EVENTS")
@Setter
@Getter
public class Event {
    @Id
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid2")
    private String id;
    private String title;
    private String description;
    @Enumerated(EnumType.STRING)
    private EventType eventType;
    @OneToMany(targetEntity = Category.class, mappedBy = "event", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<Category> categories;
}

Configuração properties

# data source
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:go-sports
spring.datasource.username=admin
spring.datasource.password=admin

# jpa
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.format_sql=true

# h2
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console

Arquivo SQL

INSERT INTO EVENTS (id, title, description,event_type) VALUES('77376a66-8300-11ec-a8a3-0242ac120002', 'CHALLENGE MTB FROM GRAMADO','BORA PEDALAR EM GRAMADO TÁ MASSA', 'BIKE_MTB');

Mensagem de erro foi aparecendo na log

resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #1 of URL [file:/Users/jeisonpereira/workspace/devWorkspace/go-sports-backend/target/classes/data.sql]: INSERT INTO EVENTS (id, title, description,event_type) VALUES('77376a66-8300-11ec-a8a3-0242ac120002', 'CHALLENGE MTB FROM GRAMADO','BORA PEDALAR EM GRAMADO TÁ MASSA', 'BIKE_MTB'); nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "EVENTS" not found; SQL statement:

Esse diz a tabela não foi encontrada mas já criei a entidade e tentando carregar dados para o banco H2