• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

object references an unsaved transient instance - save the transient instance before flushing

 
Ranch Hand
Posts: 44
1
Android Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I try to save a ChatEntry. This ChatEntry Entity does have a User (FROM) Entity and a User (TO) Entity.

ChatEntry is mapped by user with "manyToOne" relation.

User does have a "OneToMany" Relation with a list of chatEntries.

When I write a ChatEntry the User FROM and the User TO are already exisiting else it would make no sense to create them now.

This is why I don't want to use the cascade=CascadeType.ALL Annotation

ChatEntry.java


User.java


I am using the entityManager persist method to insert the new ChatEntries.


 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Kevin Olome wrote:I try to save a ChatEntry. This ChatEntry Entity does have a User (FROM) Entity and a User (TO) Entity.


And what exactly is the issue you are facing? Do you get an exception at runtime when persisting a ChatEntry instance?

Why are you using not so meaningful names as user and user1? Would it not be better to use userFrom (or from) and userTo (or to). Currently you are also returning user from the getUser1() method...
 
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic