fix(metadata): update cascade options for comic metadata relationship to include removal and orphan handling#3023
Conversation
… to include removal and orphan handling
|
Not to repeat myself, but eventually we have to get to #2670 because hibernate situation is not maintainable. We need consistency... If you indicate when I should get the PR ready, I'll do it. |
|
As for this, it's a pure guess. |
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #3000 where deleting books with comic metadata failed with a Hibernate TransientPropertyValueException. The root cause was that the cascade configuration on the BookMetadataEntity to ComicMetadataEntity relationship only included PERSIST and MERGE operations, not REMOVE. When Hibernate attempted to delete a book and its metadata, it couldn't properly cascade the deletion to the associated comic metadata, leading to inconsistent entity states during the flush operation.
Changes:
- Updated the cascade options for the
comicMetadatafield inBookMetadataEntityto includeCascadeType.REMOVEand addedorphanRemoval = true, ensuring comic metadata is properly deleted when the parent book metadata is deleted.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
booklore-api/src/main/java/org/booklore/model/entity/BookMetadataEntity.java
Outdated
Show resolved
Hide resolved
booklore-api/src/main/java/org/booklore/model/entity/BookMetadataEntity.java
Outdated
Show resolved
Hide resolved
| private BookEntity book; | ||
|
|
||
| @OneToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.LAZY) | ||
| @OneToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE}, orphanRemoval = true, fetch = FetchType.LAZY) |
There was a problem hiding this comment.
hey, thanks for looking into this! the change itself looks reasonable, CascadeType.REMOVE + orphanRemoval = true makes sense here since BookEntity already cascades ALL + orphanRemoval down to BookMetadataEntity (line 32 of BookEntity), but that cascade was stopping at BookMetadataEntity and not reaching the ComicMetadataEntity child. so deleting a book would leave orphaned comic metadata rows behind, which matches the error in #3000.
one thing though, the PR description says "possible fix" so it sounds like this is a guess. were you able to actually reproduce the issue and test the fix? the issue reporter mentioned it only happens on specific entries in their instance, so it'd be good to know if you confirmed the cascade chain works end-to-end (delete a book that has comic metadata and verify the comic_metadata row gets cleaned up too). if you haven't been able to reproduce it, totally understandable given the setup, just want to make sure we're not merging blind.
There was a problem hiding this comment.
Nope. I wasn't, essentially I looked "What's different here" that may cause problems and made educated guess there.
There was a problem hiding this comment.
I tested this, it worked, but (for me) it worked before also perfectly so that does not mean anything
There was a problem hiding this comment.
Though, we can try to give to the people a test container see where it goes? What do you think about that 🤔
There was a problem hiding this comment.
Yeah, makes sense to have the folks who reported the bug test the container first. They'd be the best ones to verify the fix.
There was a problem hiding this comment.
Sure, I think there are some useful tips for you at: https://github.com/booklore-app/booklore/blob/develop/CONTRIBUTING.md
But feel free to ask, if something not clear.
There was a problem hiding this comment.
Got a chance to build the image there and test it out. Unfortunately it hasn’t resolved the issue. The error I’m now getting is
Batch update returned unexpected row count from update 0 (expected row count 1 but was 0) [delete from comic_metadata where book_id=?] for entity [org.booklore.model.entity.ComicMetadataEntity with id '5737']
There was a problem hiding this comment.
This gave me an idea. 1 sec!
There was a problem hiding this comment.
Can you retry with this commit included: 383de22
… ensure proper join handling
📝 Description
Possible fix for: #3000
Linked Issue: Fixes #
🏷️ Type of Change
🔧 Changes
🧪 Testing (MANDATORY)
Manual testing steps you performed:
Regression testing:
Edge cases covered:
Test output:
Backend test output (
./gradlew test)Frontend test output (
ng test)📸 Screen Recording / Screenshots (MANDATORY)
✅ Pre-Submission Checklist
develop(merge conflicts resolved)🤖 AI-Assisted Contributions
TODOs, or unused scaffolding left behind by AI💬 Additional Context (optional)