java - JPA merge foreign key lost -



java - JPA merge foreign key lost -

i'm new jpa hibernate implementation , i'm trying understand how entitymanager.merge works. have next scenario of 2 classes @manytoone relation e.g

class a{ private string name; ........ get... set... } class b{ private string name; @manytoone(fetch=fetchtype.lazy, cascade=cascadetype.merge) private a; ........ get... set... }

and have gui can view , alter b property's - class not loaded , there no open session in view. when trying save(merge) changes in back-end:

entitymanager.merge(b); //the object "b" created view has "a" set null

in database in table b foreign key relationship(referencing table a) lost - set null; not want want maintain relationship , merge-save changes made in gui object b out losing many-to-one relationship maybe i'm expecting not possible , need is:

dbb b = entitymanager.find(b.class, id); dbb.setname(b.getname()); dbb.set........ entitymanager.merge(dbb);

if in entitymanager.merge(b); relation b.a null, merge delete foreign key. that's because value null doesn't mean reference should ignored reference should removed (i.e. there no reference anymore).

i want maintain relationship , merge-save changes made in gui object b out losing many-to-one relationship

one alternative read entity database a beingness initialized lazy proxy , pass gui. during process entity detached , hence need merge during save. however, since a won't null in case, reference should not lost.

java mysql hibernate jpa

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -