Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Deletando registros inseridos pelo data.sql

Quando tento fazer o delete via postman em algum registro inserido por meio do data.sql, ele mostra o seguinte erro:

Hibernate: select pet0_.id as id1_2_0_, pet0_.data_cadastro as data_cad2_2_0_, pet0_.detalhe as detalhe3_2_0_, pet0_.especie as especie4_2_0_, pet0_.idade as idade5_2_0_, pet0_.nome as nome6_2_0_, pet0_.raca as raca7_2_0_, pet0_.status as status8_2_0_, pet0_.id_tutor as id_tutor9_2_0_, tutor1_.id as id1_4_1_, tutor1_.data_cadastro as data_cad2_4_1_, tutor1_.email as email3_4_1_, tutor1_.nome as nome4_4_1_, tutor1_.status as status5_4_1_, tutor1_.telefone1 as telefone6_4_1_, tutor1_.telefone2 as telefone7_4_1_ from pets pet0_ left outer join tutores tutor1_ on pet0_.id_tutor=tutor1_.id where pet0_.id=?
Hibernate: delete from pets where id=?
2022-10-10 12:13:07.367  WARN 52696 --- [nio-8080-exec-7] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 23503, SQLState: 23503
2022-10-10 12:13:07.367 ERROR 52696 --- [nio-8080-exec-7] o.h.engine.jdbc.spi.SqlExceptionHelper   : Referential integrity constraint violation: "FKF4SM2Y3EA7ABRF9KGSTPC4B45: PUBLIC.PET_SERVICO FOREIGN KEY(ID_PET) REFERENCES PUBLIC.PETS(ID) (CAST(1 AS BIGINT))"; SQL statement:
delete from pets where id=? [23503-214]
2022-10-10 12:13:07.367  INFO 52696 --- [nio-8080-exec-7] o.h.e.j.b.internal.AbstractBatchImpl     : HHH000010: On release of batch it still contained JDBC statements
2022-10-10 12:13:07.367 ERROR 52696 --- [nio-8080-exec-7] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint ["FKF4SM2Y3EA7ABRF9KGSTPC4B45: PUBLIC.PET_SERVICO FOREIGN KEY(ID_PET) REFERENCES PUBLIC.PETS(ID) (CAST(1 AS BIGINT))"; SQL statement:
delete from pets where id=? [23503-214]]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement] with root cause

org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException: Referential integrity constraint violation: "FKF4SM2Y3EA7ABRF9KGSTPC4B45: PUBLIC.PET_SERVICO FOREIGN KEY(ID_PET) REFERENCES PUBLIC.PETS(ID) (CAST(1 AS BIGINT))"; SQL statement:
delete from pets where id=? [23503-214]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:508) ~[h2-2.1.214.jar:2.1.214]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:477) ~[h2-2.1.214.jar:2.1.214]
    at org.h2.message.DbException.get(DbException.java:223) ~[h2-2.1.214.jar:2.1.214]
    at org.h2.message.DbException.get(DbException.java:199) ~[h2-2.1.214.jar:2.1.214]
    ...

Mas quando crio um novo registro no banco, consigo excluí-lo sem problemas.

1 resposta
solução!

Oi Rebeca,

Na verdade isso tem a ver com o relacionamento entre os registros nas tabelas do banco de dados.

Você deve estar tentando excluir algum registro que está sendo referenciado em outra tabela e isso não pode ser feito, pois causaria um erro de constraint no banco de dados.