# Bad -> improved: CommentBad (cascade ALL to the author) vs Comment + Writer.comments
# Hibernate ORM 7.4.15.Final, H2, JDK 25

== Bad: a writer with two comments, delete one
-- remove(CommentBad first); flush()
   sql> select cb1_0.id,cb1_0.author_id,cb1_0.text from CommentBad cb1_0 where cb1_0.id=?
   sql> select w1_0.id,w1_0.name from Writer w1_0 where w1_0.id=?
   sql> select c1_0.author_id,c1_0.id,c1_0.text from Comment c1_0 where c1_0.author_id=?
   sql> delete from CommentBad where id=?
   sql> delete from Writer where id=?
   threw: org.hibernate.exception.ConstraintViolationException <- org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException
   cause: Referential integrity constraint violation: "FKI5Y1RDJMEQ4UP89E3R112XDIT: PUBLIC.COMMENTBAD FOREIGN KEY(AUTHOR_ID) REFERENCES PUBLIC.WRITER(ID) (CAST(1 AS BIGINT))"; SQL statement:
raw rows after rollback: Writer=1 CommentBad=2

== Improved: cascade flows down from Writer to Comment, never up
-- remove(Comment one); flush()
   sql> select c1_0.id,c1_0.author_id,c1_0.text from Comment c1_0 where c1_0.id=?
   sql> delete from Comment where id=?
raw rows: Writer(bob)=1 Comment=1
-- remove(Writer bob); flush()  (cascade ALL downward)
   sql> select w1_0.id,w1_0.name from Writer w1_0 where w1_0.id=?
   sql> select c1_0.author_id,c1_0.id,c1_0.text from Comment c1_0 where c1_0.author_id=?
   sql> delete from Comment where id=?
   sql> delete from Writer where id=?
raw rows: Comment=0
