• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Kevin Olome
Ranch Hand
Posts: 41
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.


 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • 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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic