mysql - Synchronization error occurs while running my program -


i using jsf2.0/primefaces , mysql, glassfish3.1 .

i have 3 tables: person, file, domainecompetence

person(name,......,iddomainecompetence)

file(idfile,namefile,......,idperson)

domainecompetence(iddomainecompetence.....)

when person added database in same time row added file table.

but error occurs after submitting. have 2 errors. dont know why 1 of them (not both in same time) appear after execute program.

the index.xhtml:

<h:form>      <p:panel header="add user"    style="width: 500px; font-size: 14px">        <h:panelgrid width="width: 300px;"    columns="2">             <h:outputlabel style="font-size: 13px" value="nom" /> <h:inputtext value="#{addperson.nom}" />           <h:outputlabel value="prenom"/> <h:inputtext value="#{addperson.prenom}" />           <h:outputlabel value="etat civil"/>           <h:selectonemenu id="etatcivil" value="#{addperson.etatcivil}">               <f:selectitem itemvalue="monsieur" itemlabel="m"/>               <f:selectitem itemvalue="madam" itemlabel="mme"/>               <f:selectitem itemvalue="madmoiselle" itemlabel="mlle"/>            </h:selectonemenu>             <h:outputlabel value="date de naissance "/>              <p:calendar value="#{addperson.datenaissance}" id="popupbuttoncal" showon="button" />              <h:outputlabel value="email"/><h:inputtext value="#{addperson.email}" />              <h:outputlabel value="numtelephone"/><h:inputtext value="#{addperson.numtelephone}" />              <h:outputlabel value="mobile"/><h:inputtext value="#{addperson.mobile}" />              <h:outputlabel value="fax"/><h:inputtext value="#{addperson.fax}" />              <h:outputlabel value="profession"/><h:inputtext value="#{addperson.profession}" />              <h:outputlabel value="adresse"/><h:inputtext value="#{addperson.adresse}" />              <h:outputlabel value="code postal"/><h:inputtext value="#{addperson.codepostal}" />              <h:outputlabel value="ville"/><h:inputtext value="#{addperson.ville}" />               <h:outputlabel value="pays"/><h:inputtext value="#{addperson.pays}" />                 <h:outputlabel value="domaine de competence"/>                  <h:selectonemenu  value="#{addperson.domain}" id="domaine" >                   <f:selectitem itemlabel="-- select domaine de competence-- " itemvalue="0"/>                    <f:selectitems value="#{addperson.listdomaine}" />                  </h:selectonemenu>                  <h:outputlabel value="login"/><h:inputtext value="#{addperson.login}" />                <h:outputlabel value="password"/><h:inputtext value="#{addperson.password}" />                <p:fileupload fileuploadlistener="#{addperson.fileupload}"   update="messages"   sizelimit="500000"    allowtypes="/(\.|\/)(gif|jpe?g|png)$/"/>                  <h:commandbutton action="#{addperson.adduserdb}"  value="add user" />                </h:panelgrid>      </p:panel>  </h:form> 

bean addperson.java:

public class addperson implements serializable{         entitymanagerfactory emf = persistence.createentitymanagerfactory("testpu");    entitymanager em = emf.createentitymanager();      private string nom;    private string prenom;    private date datenaissance;    private string lieunaissance;    private string etatcivil;    private string email;    private int  numtelephone;    private int  mobile;    private int fax;    private string profession;    private string login;    private string  password;    private string adresse;    private int codepostal;    private string ville;    private string pays;    private fileuploadevent event;    private file file;    private static list<selectitem> listdomaine;    private string domain;      //getters , setters       public void fileupload(fileuploadevent event) throws ioexception {      string path = facescontext.getcurrentinstance().getexternalcontext().getrealpath("/");      simpledateformat fmt = new simpledateformat("yyyymmddhhmmss");      string name = fmt.format(new date())+ event.getfile().getfilename().substring(event.getfile().getfilename().lastindexof('.'));      file = new file("c:/users/documents/netbeansprojects/test/uploaded files/" + name);       inputstream = event.getfile().getinputstream();      outputstream out = new fileoutputstream(file);         byte buf[] = new byte[1024];       int len;        while ((len = is.read(buf)) > 0)          out.write(buf, 0, len);        is.close();       out.close();     }      public list<selectitem> getlistdomaine() {      finddomaine fdom= new finddomaine();       if (listdomaine == null) {         listdomaine = new arraylist<selectitem>();         (string val : fdom.findalldomaine()) {             listdomaine.add(new selectitem(val));         }     }     return listdomaine;   }       public void adduserdb() {       try {          entitytransaction entr = em.gettransaction();         entr.begin();          personne user = new personne();         fileuploaded fileup =new fileuploaded();         domainecompetence dom=new domainecompetence();         user.setnom(nom);         user.setprenom(prenom);         user.setcodepostal(codepostal);         user.setemail(email);         user.setetatcivil(etatcivil);         user.setfax(fax);         user.setlieunaissance(lieunaissance);         user.setdatenaissance(datenaissance);         user.setmobile(mobile);         user.setadresse(adresse);         user.setpays(pays);         user.setlogin(login);         user.setpassword(password);         user.setpassword(password);         fileup.setfilename(file.getname());         fileup.setfilepath(file.getpath());         fileup.setidpersonne(user);//add forign key table fileupload         user.setdomaine(dom);        system.out.println("+++++test+++++"+this.nom);       system.out.println("++++++test++++"+this.prenom);       system.out.println("++++++test++++"+this.domain);           em.persist(user);         em.persist(fileup);         entr.commit();     } catch (exception e) {         system.out.println(e.getmessage());         system.out.println("failed");     } {         em.close();     }     }  }   

persistance.xml

<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">  <persistence-unit name="testpu" transaction-type="resource_local">  <provider>org.eclipse.persistence.jpa.persistenceprovider</provider>  <class>dto.domainecompetence</class>  <class>dto.personne</class>  <exclude-unlisted-classes>false</exclude-unlisted-classes>  <validation-mode>none</validation-mode>  <properties>   <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/test"/>   <property name="javax.persistence.jdbc.password" value="root"/>   <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.driver"/>   <property name="javax.persistence.jdbc.user" value="root"/>  </properties>  </persistence-unit> </persistence> 

error1:

infos: initialisation de mojarra 2.1.3 (fcs b02) pour le contexte «/test» infos: instantiated instance of org.hibernate.validator.engine.resolver.jpatraversableresolver. infos: monitoring jndi:/server/test/web-inf/faces-config.xml modifications infos: web0671: loading application [test] @ [/test] infos: test été déployé en 3 485 ms. infos: file datejava.text.simpledateformat@5069d960 infos: file name :20120308103902.gif infos: ++++++++++julie infos: ++++++++++julie infos: ++++++++++securite informatique infos: object: dto.personne[ idpersonne=null ] not known entity type. infos: failed 

error 2:

infos: file datejava.text.simpledateformat@5069d960 infos: file name :20120308102712.gif infos: base de donnee infos: ++++++++++julie infos: ++++++++++julie infos: ++++++++++base de donnee infos: [el warning]: 2012-03-08 10:27:15.604--unitofwork(5810583)--java.lang.illegalstateexception: during synchronization new object found through relationship not marked cascade persist: dto.domainecompetence[ domaine=null ].  infos: java.lang.illegalstateexception: during synchronization new object found through relationship not marked cascade persist: dto.domainecompetence[ domaine=null ]. infos: failed infos: pwc2785: cannot serialize session attribute addperson session 1a185521c447acaa561b45f616d7 

personne.java

@entity @table(name = "personne", catalog = "test", schema = "", uniqueconstraints = { @uniqueconstraint(columnnames = {"idpersonne"})}) @xmlrootelement @namedqueries({ @namedquery(name = "personne.findall", query = "select p personne p"), @namedquery(name = "personne.findbyidpersonne", query = "select p personne p   p.idpersonne = :idpersonne"), @namedquery(name = "personne.findbynom", query = "select p personne p p.nom = :nom"),  @joincolumn(name = "domaine", referencedcolumnname = "domaine")  @manytoone  private domainecompetence domaine; 

update:

domainecompetence.java

@entity @table(name = "domainecompetence", catalog = "test", schema = "") @xmlrootelement @namedqueries({ @namedquery(name = "domainecompetence.findall", query = "select d domainecompetence d"), @namedquery(name = "domainecompetence.findbydomaine", query = "select d domainecompetence d d.domaine = :domaine")}) public class domainecompetence implements serializable { private static final long serialversionuid = 1l; @id @basic(optional = false) @notnull @size(min = 1, max = 200) @column(name = "domaine", nullable = false, length = 200) private string domaine; @onetomany(cascade = cascadetype.persist, mappedby = "domaine") //and have tried cascadtype.all private collection<personne> personnecollection; //getters , setters 

}

regarding second error:

you try persist entity (personne) has entity (domaincompetence) attached through relation in entity class. did not set relation cascade=persist or cascade=all. entitymanager doesn't know entity. here example how cascade attribute can set:

@onetomany(cascade = cascadetype.all, mappedby = "...") private list<personne> personnelist; 

look domaincompetence entity class , change accordingly. hope helps bit further.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -