java - JPA persist many to many Fetch=FetchType.Lazy -


i have pretty standard scenario whereby have table of employe , table of unite ewith . 2 tables related via many many relationship (ie. emoloye can have many unite , unite can applied many employe) , subsequently have joining table called effectif_unite. 2 columns . have generated entity classes (see below) , have no problem persisting data employe , unite tables have failed miserably persist employe_has_unite .

// method en application client

public void add(int mat, string grade, string fonction, int cnprs, int cin, string np, string adress, string tel, int disp, date date, arraylist uns) {     employe emp = new employe();     grade gr = bean.grade_emp(grade);     fonction f = bean.fonction_emp(fonction);     emp.setmatemp(mat);      emp.setnumgrd(gr.getnumgrd());     emp.setnumfon(f.getnumfon());     emp.setcnprs(cnprs);     emp.setcin(cin);     emp.setadress(adress);     emp.settel(tel);     emp.setnp(np);     emp.setdispo(disp);     emp.setdtrt(date);     emp.setunitelist(uns); // affect list<unite> employe here!!      bean.add(emp);     }  // dao public void add(employe e,arraylist<unite> uns) {  /* entitytransaction et = em.gettransaction(); et.begin(); em.persist(e); et.commit();     */ entitytransaction ett = em.gettransaction(); ett.begin(); effectifunite u=new effectifunite();  u.setunite(uns.get(0)); u.setemploye(em.find(employe.class, 1)); effectifunitepk pk= new effectifunitepk(); pk.setmatemp(em.find(employe.class, 1).getmatemp()); pk.setnumunt(uns.get(0).getnumunt()); u.seteffectifunitepk(pk);   em.persist(u); ett.commit(); } 


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -