开发者

JPA/Glassfish 3.0.1 java.lang.IllegalStateException: During synchronization

开发者 https://www.devze.com 2023-02-01 03:56 出处:网络
My class model contains a class that has relationship tagged with annotations. I took care to use them correctly by adding the famous \"cascade=cascadeType.PERSIST\". Sometimes it works, but, very oft

My class model contains a class that has relationship tagged with annotations. I took care to use them correctly by adding the famous "cascade=cascadeType.PERSIST". Sometimes it works, but, very often not, I get this error message :

"java.lang.IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: Model.Donation[id=null]."

I found on several web sites that comes from the library but without more explication...

Thank you for your help

@OneToOne(optional=true, cascade=CascadeType.ALL)
private Localisation localisation;
@ManyToOne(cascade=CascadeType.ALL)
private Device device;
@ManyToOne(cascade=CascadeType开发者_如何学Go.ALL)
private Project project;


As my relationships are bi-directional, I though I only need to set cascadeType to the relationship that manages the relation. But it isn't. By adding cascadeType.ALL to the both sides, it works perfectly!

0

精彩评论

暂无评论...
验证码 换一张
取 消