TransientObjectException ☕ Java

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.

Seen on: Java

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

  1. Save the referenced entity first
  2. Add cascade on the owning relation
  3. Load existing entities with getReferenceById instead of new

Detailed fix by platform

Java

  1. @OneToMany(mappedBy = "order", cascade = CascadeType.ALL)

How to diagnose

  1. Reference — Which entity is transient?
  2. Cascade — Configured on that relation?

🧠 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.