Fix JPA error of not being able to find ID
Describe the bug
updateAuthorAffectsOneRow fails in AuthorTest.
[ERROR] updateAuthorAffectsOneRow Time elapsed: 0 s <<< ERROR!
org.springframework.orm.jpa.JpaObjectRetrievalFailureException: Unable to find com.karankumar.bookproject.backend.entity.Book with id 25; nested exception is javax.persistence.EntityNotFoundException: Unable to find com.karankumar.bookproject.backend.entity.Book with id 25
at com.karankumar.bookproject.backend.entity.AuthorTest.updateAuthorAffectsOneRow(AuthorTest.java:73)
Caused by: javax.persistence.EntityNotFoundException: Unable to find com.karankumar.bookproject.backend.entity.Book with id 25
at com.karankumar.bookproject.backend.entity.AuthorTest.updateAuthorAffectsOneRow(AuthorTest.java:73)
To Reproduce Steps to reproduce the behaviour:
- Run
mvn clean install
Expected behaviour
No errors. Test passes.
Hi Karan, can I work on this? I think both the test cases in AuthorTest needs a fix.
Thanks, Diego
Hi Diego. Sure, that would help a lot! Thanks!
An update (sorry but I've been busy lately):
- the problem is not only in AuthorTest.java but also in BookServiceTest.validBookSaved() if you try to save the same book 2 times it will throw the same exception.
I'm looking to reproduce the same exception in a simpler setting.
Bye, Diego
Thanks for the update, @inhundreds!
Hello Karan, the problem in AuthorTest is that the toRead object keeps a reference to a book that is removed with the resetBookService() method.
Fixing this, though, I found that the beRemovedWhenOrphan test is also broken. It assumes that authors without books are removed from the repository but I can't find this implementation anywhere in the code. That test was working by chance.
I suggest to remove it, but let me know what do you think about it.
Thanks, Diego
@inhundreds Thanks for the update, Diego. I'll take a look at this over the weekend.
@schrothbn I think you noticed the same thing?
@knjk04 Yes that's true. Actually that test was working on PR #485 because i needed to change the test setup for fixing the test in the ticket. Was done on an now older version of master though, something might've broken it since then.
@inhundreds Have you tried this on master? Perhaps you don't have @schrothbn's change
@knjk04 Now it is ok so I think you can close this issue.
@inhundreds Thanks
Got this issue again on spring boot build 3.0.0-SNAPSHOT. Currently have a Student Transaction and then linked to transaction class:
@Id @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER, optional = false, orphanRemoval = true) @JoinColumn(name = "transaction_id", referencedColumnName = "id") @ExcelColumn(title = "Transaction Information", recurse = true) @Validation(required = true, message = "Failed to create transaction") private Transaction transaction;
Unable to find za.co.silversurge.jezportal.models.Transaction with id 302
Transaction in the database :
302,1,2000,0,2022-12-28 20:55:14.000000,0,BiLlbnkzdc,OR306nCN,CASH
Hi @JpSilver, thanks for letting us know you still face this problem.
Unfortunately, I will be archiving this project as I no longer have the time to maintain it.