Estou com erro ao executar a opção 2 do menu, depois de informar o nome da Série. Estou comparando o meu código com o Github mas não encontro diferenças no código.
o Erro:
Hibernate: insert into episodios (avaliacao,data_lancamento,numero_episodio,serie_id,temporada,titulo) values (?,?,?,?,?,?)
2024-01-03T12:12:21.740-03:00 WARN 21571 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 23502
2024-01-03T12:12:21.740-03:00 ERROR 21571 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : ERROR: null value in column "id" of relation "episodios" violates not-null constraint
Detalhe: Failing row contains (null, 9, 2008-01-20, 1, 1, Pilot, 4).
2024-01-03T12:12:21.745-03:00 INFO 21571 --- [ main] .s.b.a.l.ConditionEvaluationReportLogger :
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2024-01-03T12:12:21.753-03:00 ERROR 21571 --- [ main] o.s.boot.SpringApplication : Application run failed
java.lang.IllegalStateException: Failed to execute CommandLineRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:774) ~[spring-boot-3.1.1.jar:3.1.1]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:755) ~[spring-boot-3.1.1.jar:3.1.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:319) ~[spring-boot-3.1.1.jar:3.1.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-3.1.1.jar:3.1.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-3.1.1.jar:3.1.1]
at br.com.alura.screenmatch.ScreenmatchApplication.main(ScreenmatchApplication.java:17) ~[classes/:na]
Caused by: org.springframework.dao.DataIntegrityViolationException: could not execute statement [ERROR: null value in column "id" of relation "episodios" violates not-null constraint
Detalhe: Failing row contains (null, 9, 2008-01-20, 1, 1, Pilot, 4).] [insert into episodios (avaliacao,data_lancamento,numero_episodio,serie_id,temporada,titulo) values (?,?,?,?,?,?)]; SQL [insert into episodios (avaliacao,data_lancamento,numero_episodio,serie_id,temporada,titulo) values (?,?,?,?,?,?)]; constraint [id" of relation "episodios]
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:269) ~[spring-orm-6.0.10.jar:6.0.10]
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:229) ~[spring-orm-6.0.10.jar:6.0.10]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:550) ~[
2024-01-03T12:12:21.757-03:00 INFO 21571 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2024-01-03T12:12:21.759-03:00 INFO 21571 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2024-01-03T12:12:21.764-03:00 INFO 21571 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
Classe serie:
@Entity
@Table(name = "series")
public class Serie {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(unique = true)
private String titulo;
private Integer totalTemporadas;
private Double avaliacao;
@Enumerated(EnumType.STRING)
private Categoria genero;
private String atores;
private String poster;
private String sinopse;
@OneToMany(mappedBy = "serie", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<Episodio> episodios = new ArrayList<>();
public void setEpisodios(List<Episodio> episodios) {
episodios.forEach(e -> e.setSerie(this));
this.episodios = episodios;
}
}
Classe Episodio
@Entity
@Table(name = "episodios")
public class Episodio {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Integer temporada;
private String titulo;
private Integer numeroEpisodio;
private Double avaliacao;
private LocalDate dataLancamento;
@ManyToOne
private Serie serie;
public Episodio() {}
}