org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing
An entity references another entity that hasn’t been saved yet, and no cascade is configured.
object references an unsaved transient instance Meaning
Hibernate won’t persist the referenced object implicitly unless the relationship cascades PERSIST/ALL.
Common causes
- New child/parent not saved before flush
- Missing cascade = CascadeType.PERSIST
- Detached vs new instance confusion
⚡ Quick fix
- Save the referenced entity first
- Add cascade on the owning relation
- Load existing entities with getReferenceById instead of new
Detailed fix by platform
Java
@OneToMany(mappedBy = "order", cascade = CascadeType.ALL)
How to diagnose
- Reference — Which entity is transient?
- Cascade — Configured on that relation?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- Hibernate ConstraintViolationException org.hibernate.exception.ConstraintViolationException: could not execute statement
- LazyInitializationException org.hibernate.LazyInitializationException: could not initialize proxy - no Session
- N+1 queries Performance: N+1 query problem (one query per row in a loop)
Most viewed in Java
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 13 Oct 2026