0

I have:

Document ManyToOne Template

When I click save Template see error, I try add @JsonIgnore then OK but this entity not show in UI

Document.Java

@ManyToOne(cascade = CascadeType.MERGE)
//cascade = CascadeType.PERSIST or cascade = CascadeType.ALL not success
@JoinColumn(name = "template_id")
private Template template;

Error

{"timestamp":"2017-03-29T04:03:30.553+0000","status":500,"error":"Internal Server Error","exception":"org.springframework.dao.InvalidDataAccessApiUsageException","message":"org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing : com.paragonsystem.capture.domain.Document.template -> com.paragonsystem.capture.domain.Template; nested exception is java.lang.IllegalStateException: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing : com.paragonsystem.capture.domain.Document.template -> com.paragonsystem.capture.domain.Template","path":"/api/documents"}
Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
phong pham
  • 11
  • 5
  • 2
    Possible duplicate of [object references an unsaved transient instance - save the transient instance before flushing](http://stackoverflow.com/questions/2302802/object-references-an-unsaved-transient-instance-save-the-transient-instance-be) – soorapadman Mar 29 '17 at 04:14
  • I try cascade = {CascadeType.ALL} or cascade = CascadeType.PERSIST not success, if add them then template save OK but in document not save – phong pham Mar 29 '17 at 04:22
  • {"timestamp":"2017-03-29T04:21:46.898+0000","status":500,"error":"Internal Server Error","exception":"org.springframework.dao.InvalidDataAccessApiUsageException","message":"detached entity passed to persist: com.paragonsystem.capture.domain.Template; nested exception is org.hibernate.PersistentObjectException: detached entity passed to persist: com.paragonsystem.capture.domain.Template","path":"/api/documents"} – phong pham Mar 29 '17 at 04:22
  • ok then make sure before saving both object not null . – soorapadman Mar 29 '17 at 04:23
  • Yes, I think issue in private Template template; – phong pham Mar 29 '17 at 04:29
  • I have came across this issue many times – soorapadman Mar 29 '17 at 04:29
  • You can help me fix this issue, I search and fix 2 days but not resolved – phong pham Mar 29 '17 at 04:34
  • I happy to do that .As i told you that this error happens whenever you try to save the Object without saving the appropriate Joins. So make sure before persist all the join object you are setting.I mean both way you need to set. – soorapadman Mar 29 '17 at 04:39
  • I think if you have TeamViewer you can explain persist for me understand, I feel I can't fix this bug because I spend much time on this issue but can't don't understand them – phong pham Mar 29 '17 at 04:50
  • Template not posted in the question. Persistence code not posted in the question. JSON is utterly irrelevant to the problem. Debug it using the LOG! – Neil Stockton Mar 29 '17 at 06:16
  • '@JsonIgnore' flags a field not be serialized into a JSON to avoid cyclic references. It could indicate another problem, post contents of 'Document' and 'Template' classes if is this question still open, otherwise, close it. – Tomas F. Mar 29 '17 at 11:22

0 Answers0