Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

@OneToMany, detached adding an object to the list -> org.hibernate.TransientObjectException

 
Ranch Hand
Posts: 153
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a class A which has a .



I use it in an web application, so A becomes detached. The User can add B instances to A.
When I try to merge A which reference a new B instance I get

Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: B

Is this the expected behavior for JPA 2.0?

Do I have to write code to save B before saving A or this there some way to automate this with the right mapping annotations?

Thanks,

Hans
 
Markus Schmider
Ranch Hand
Posts: 153
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok I have found out for myself:

You have to add a CascadeType



 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic