when trying to access a mapped collection:
@OneToMany(cascade = CascadeType.ALL, mappedBy = "cmTypedef")
private ListcmParamdefs;
I instantiated a object, then em.merge() it but still I got a NPE.
I really thought that merge would populate all the fields.
Then I tried to make it Eager:
@OneToMany(cascade = CascadeType.ALL, mappedBy = "cmTypedef",Still no luck :(
fetch = FetchType.EAGER)
private ListcmParamdefs = new ArrayList ();
So merge didn't do the trick, but trying everything I saw that if I do
em.flush();after the merge, then like magic the collection is populated..
em.refresh(ret);
Finally I remember I had this issue before and the simple solution I have so far is
to manually instantiate the collection:
@OneToMany(cascade = CascadeType.ALL, mappedBy = "cmTypedef")
private ListcmParamdefs = new ArrayList ();
I'm not sure if this is the best practice, but it works and is simple..
Thanks it helped to me fix the issue.
ReplyDelete