-
Notifications
You must be signed in to change notification settings - Fork 53
Hibernate Lazy fetching and Nested Models
SimpleReport uses the Hibernate ORM. When working with nested models you might find the situation that the object has only been partially instantiated. For example, when retrieving a TextMessageSent
object you will notice that the PatientLink reference will display as null even though a record does exist in the patient_link table for the TextMessageSent instance. This normally happens because the model has been configured to fetch in Lazy mode @ManyToOne(optional = true, fetch = FetchType.LAZY)
. Lazy fetching tells hibernate to only retrieve the information of the table that matches the model and to not perform joins to retrieve the information needed to populated the nested models.
If you need to enable the fetching of records across multiple tables so the nested objects get fully populated then you will need to add a @EntityGraph
annotation to the method that is performing that specific fetch in in the repo class.
For example, to enable fetching if we would like to get the TextMessageSent
instances fully populated when using the method findByTwilioMessageId
the @EntityGraph
annotation would look like this.
public interface TextMessageSentRepository extends AuditedEntityRepository<TextMessageSent> {
@EntityGraph(attributePaths = {"patientLink.testOrder.patient.phoneNumbers"})
TextMessageSent findByTwilioMessageId(String id);
}
Where patientLink.testOrder.patient.phoneNumbers
is the chain of nested objects we want to receive populated. This will enable eager fetching just for this method.
- Getting Started
- [Setup] Docker and docker compose development
- [Setup] IntelliJ run configurations
- [Setup] Running DB outside of Docker (optional)
- [Setup] Running nginx locally (optional)
- [Setup] Running outside of docker
- Accessing and testing weird parts of the app on local dev
- Accessing patient experience in local dev
- API Testing with Insomnia
- Cypress
- How to run e2e locally for development
- E2E tests
- Database maintenance
- MailHog
- Running tests
- SendGrid
- Setting up okta
- Sonar
- Storybook and Chromatic
- Twilio
- User roles
- Wiremock
- CSV Uploader
- Log local DB queries
- Code review and PR conventions
- SimpleReport Style Guide
- How to Review and Test Pull Requests for Dependabot
- How to Review and Test Pull Requests with Terraform Changes
- SimpleReport Deployment Process
- Adding a Developer
- Removing a developer
- Non-deterministic test tracker
- Alert Response - When You Know What is Wrong
- What to Do When You Have No Idea What is Wrong
- Main Branch Status
- Maintenance Mode
- Swapping Slots
- Monitoring
- Container Debugging
- Debugging the ReportStream Uploader
- Renew Azure Service Principal Credentials
- Releasing Changelog Locks
- Muting Alerts
- Architectural Decision Records
- Backend Stack Overview
- Frontend Overview
- Cloud Architecture
- Cloud Environments
- Database ERD
- External IDs
- GraphQL Flow
- Hibernate Lazy fetching and nested models
- Identity Verification (Experian)
- Spring Profile Management
- SR Result bulk uploader device validation logic
- Test Metadata and how we store it
- TestOrder vs TestEvent
- ReportStream Integration
- Feature Flag Setup
- FHIR Resources
- FHIR Conversions
- Okta E2E Integration
- Deploy Application Action
- Slack notifications for support escalations
- Creating a New Environment Within a Resource Group
- How to Add and Use Environment Variables in Azure
- Web Application Firewall (WAF) Troubleshooting and Maintenance
- How to Review and Test Pull Requests with Terraform Changes