java - Eclipselink with eclipselink tries insert in the parent table, -


i stuck following problem:

everytime try create bloco, eclipselink tries insert condominio record (which should null ) , when run same code in simple java project (without spring) works fine, in web project keeps trying insert in "parent" table.

any reason why eclipselink trying force bidirectional relationship?

entities

condominio

private static final long serialversionuid = 1l; @id @generatedvalue(strategy = generationtype.identity) @basic(optional = false) @column(name = "idcondominio") private integer idcondominio; @basic(optional = false) @column(name = "nomecond") private string nomecond; @column(name = "cnpjcond") private integer cnpjcond; @onetomany(mappedby = "condominio") private collection<bloco> blococollection; 

bloco

private static final long serialversionuid = 1l; @embeddedid protected blocopk blocopk; @basic(optional = false) @column(name = "nomebloco") private string nomebloco; @column(name = "numero") private string numero; @joincolumn(name = "condominio_idcondominio", referencedcolumnname = "idcondominio", insertable = false, updatable = false) @manytoone(optional = false) private condominio condominio; 

============================== create method

public void create(bloco bloco) throws preexistingentityexception, exception {     if (bloco.getblocopk() == null) {         bloco.setblocopk(new blocopk());     }     bloco.getblocopk().setcondominioidcondominio(bloco.getcondominio().getidcondominio());     entitymanager em = null;     try {         em = getentitymanager();         em.gettransaction().begin();         condominio condominio = bloco.getcondominio();         if (condominio != null) {             condominio = em.getreference(condominio.getclass(), condominio.getidcondominio());             bloco.setcondominio(condominio);         }         em.persist(bloco);         if (condominio != null) {             condominio.getblococollection().add(bloco);             condominio = em.merge(condominio);         }         em.gettransaction().commit();     } catch (exception ex) {         if (findbloco(bloco.getblocopk()) != null) {             throw new preexistingentityexception("bloco " + bloco + " exists.", ex);         }         throw ex;     } {         if (em != null) {             em.close();         }     } } 

========================= controller method

@requestmapping(value = "cadbloco", method = requestmethod.post) public string cadbloco(@modelattribute(value = "bloco") bloco bloco, @requestparam("condid") int idcond ) throws exception {      blocojpacontroller jpa = new blocojpacontroller();     condominio c = new condominio();     c.setidcondominio(idcond);     jpa.create(bloco);      return ("redirect:bloco.htm");  } 

=====================

ype exception report

message request processing failed; nested exception javax.persistence.rollbackexception: exception [eclipselink-4002] (eclipse persistence services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.databaseexception

description server encountered internal error prevented fulfilling request.

exception

org.springframework.web.util.nestedservletexception: request processing failed; nested exception javax.persistence.rollbackexception: exception [eclipselink-4002] (eclipse persistence services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.databaseexception internal exception: com.mysql.jdbc.exceptions.jdbc4.mysqlintegrityconstraintviolationexception: column 'nomecond' cannot null error code: 1048 call: insert condominio (cnpjcond, nomecond) values (?, ?) bind => [2 parameters bound] query: insertobjectquery(entity.condominio[ idcondominio=null ]) org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:973) org.springframework.web.servlet.frameworkservlet.dopost(frameworkservlet.java:863) javax.servlet.http.httpservlet.service(httpservlet.java:648) org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:837) javax.servlet.http.httpservlet.service(httpservlet.java:729) org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) org.netbeans.modules.web.monitor.server.monitorfilter.dofilter(monitorfilter.java:393)

the exception says "nomecond" value null. in controller if add code says

c.setnomecond("some value");

that should fix issue.,


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -