0

I do have a system running on Apache tomcat 7 (7.0.34 if that makes any difference) with a mapping with a property like this

@OneToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST,CascadeType.MERGE})
@JoinTable(name = "device_document",
    joinColumns = {@JoinColumn(name = "device_id", referencedColumnName = "device_id")},
    inverseJoinColumns = @JoinColumn(name = "document_id", referencedColumnName = "id"))
public Set<Document> getDocuments() {
    return documents;
}

When I do call to my save function it works nice, but after some time the exact same code, with the exact same data throws an exception

unsaved transient instance - save the transient instance before flushing

And it keeps throwing that exception everytime I try to save the instance until (sometimes) I restart the tomcat service.

Do you have any idea about why is this happening?

  • the usual posts about "unsaved transient instance error" reads this is about cascading, but already tried to set CascadeType to all and it is the same – aldo.lares Sep 26 '13 at 22:08

1 Answers1

0

What method are you using to save? saveOrUpdate?

Does it throw "unsaved transient instance" only when you add Documents to an already save parent entity?

Try to add CascadeType.UPDATE to your OneToMany annotation.

Manuel Darveau
  • 4,585
  • 5
  • 26
  • 36
  • I'm using saveOrUpate, and it happens on both cases, when adding a new parent with documents added, or updating some parent already saved, i'm gonna try the CascadeType to Update to check if that works, but today i found that my makePersistent makes flush after doing saveOrUpdate, so, i will put flush before that – aldo.lares Sep 27 '13 at 14:19