-
Notifications
You must be signed in to change notification settings - Fork 3
Fix lazy loading issue in test base class causing spurious test failures #306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: rvosa <[email protected]>
|
@copilot we're still getting these failures: |
…ialization issues The previous fix using load() with ObjectNotFoundException catch didn't work because load() returns a proxy object that only throws ObjectNotFoundException when properties are accessed later. Using get() instead immediately queries the database and returns null if the entity doesn't exist, preventing the exception from occurring in test code. Co-authored-by: rvosa <[email protected]>
... Fixed in commit 1e1e8f1. The issue was that |
Tests using
AbstractDAOTest.loadObject()were failing with uncaughtObjectNotFoundExceptionwhen database entities didn't exist, instead of gracefully skipping as intended.Changes
AbstractDAOTest.loadObject()to usehibernateTemplate.get()instead ofhibernateTemplate.load()nullimmediately when entities don't exist, preventing lazy loading exceptionsTechnical Details
Hibernate's
hibernateTemplate.load()returns a lazy proxy object even when an entity doesn't exist in the database. TheObjectNotFoundExceptionis only thrown later when properties are accessed on this proxy, not during theload()call itself. This caused exceptions to occur in test code rather than being handled inloadObject().The solution uses
hibernateTemplate.get()instead, which:nullif the entity doesn't exist (no proxy created)ObjectNotFoundExceptionfrom being thrown later in test codeAll affected tests already check for
nulland skip with "empty database, test skipped" messages - they just needed the entity loading to returnnullinstead of a proxy that throws exceptions.Impact
Fixes 6 failing tests that expect entities with specific IDs (Matrix #265, #683, Study #794, #586). Applies to all 40 test classes extending
AbstractDAOTest.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.