Wednesday 15 May 2013

java - JPA insertion in the database failed -



java - JPA insertion in the database failed -

i have problem when seek insert info database. doing jpa (persist). here code phone call method insert

private static serviceticketremote serviceticket; ...... ...... public void insertdevices(actionevent acteven) { java.sql.date sqldate = new java.sql.date(datedev.gettime()); if(modele.equals("")|| serialnumber.equals("") || sqldate.equals("") || categorie.equals("select device")) { facesmessage msg = new facesmessage(facesmessage.severity_error, "champ(s) vide(s)", ""); facescontext.getcurrentinstance().addmessage(null, msg); } else { devices device = new devices(); personnel = getbeanlogin().getagentsupport(); agentinfo agent = getbeanagentinfo().getselectedagentinfo(); device.setagentinfo(agent); device.setpersonnel(as); device.setcategorie(categorie); device.setmodele(modele); device.setnumeroserie(serialnumber); device.setdateenvoi(sqldate); seek { serviceticket.insertdevices(device); facescontext.getcurrentinstance().addmessage(null, new facesmessage (facesmessage.severity_info,"device added", "")); } catch(exception e) { system.out.println("##########error########createpers()########loginbean#######" + e.getmessage()); facesmessage msg = new facesmessage(facesmessage.severity_error,"echec de l'ajout : error", e.getmessage()); facescontext.getcurrentinstance().addmessage(null, msg); } } }

and in class serviceticketremote have method insertdevices (devices device) phone call this:

@persistencecontext(unitname = "jpa") private entitymanager em; @override public devices insertdevices(devices device) { seek { em.persist(device); } grab (exception e) { system.out.println("##error# insertnewticketting " + e.getmessage());} homecoming device; }

and entity bean devices:

@entity public class devices implements serializable { private static final long serialversionuid = 1l; @id @generatedvalue(strategy=generationtype.auto) @column(name="id_device") private int iddevice; //bi-directional many-to-one association agentinfo @manytoone(fetch=fetchtype.lazy) @joincolumn(name="id_agentinfo") private agentinfo agentinfo; //bi-directional many-to-one association personnel @manytoone(fetch=fetchtype.lazy) @joincolumn(name="id_per") private personnel personnel; @column(name="categorie") private string categorie; @column(name="modele") private string modele; @column(name="numero_serie") private string numeroserie; @temporal(temporaltype.timestamp) @column(name="date_envoi") private date dateenvoi; public double getiddevice() { homecoming iddevice; } public void setiddevice(int iddevice) { this.iddevice = iddevice; } public agentinfo getagentinfo() { homecoming agentinfo; } public void setagentinfo(agentinfo agentinfo) { this.agentinfo = agentinfo; } public personnel getpersonnel() { homecoming personnel; } public void setpersonnel(personnel personnel) { this.personnel = personnel; } public string getcategorie() { homecoming categorie; } public void setcategorie(string categorie) { this.categorie = categorie; } public string getmodele() { homecoming modele; } public void setmodele(string modele) { this.modele = modele; } public string getnumeroserie() { homecoming numeroserie; } public void setnumeroserie(string numeroserie) { this.numeroserie = numeroserie; } public date getdateenvoi() { homecoming dateenvoi; } public void setdateenvoi(date dateenvoi) { this.dateenvoi = dateenvoi; } }

when run application, shows "device added", don't have errors, seems working fine have nil in database, no insertion.

can help me solve problem???

just wild guess: ejb references should not declared static.

private static serviceticketremote serviceticket;

try changing to:

private serviceticketremote serviceticket;

and see happens.

java jpa

No comments:

Post a Comment