I m using a simple relationship of a parent and a child.
The child is "Biographie" and the parent is "Auteur".
When i want to update my parent, i got :
java.sql.SQLException: Cannot insert the value NULL into column 'Auteur_ID', table 'HetCJacques.dbo.Biographie'; column does not allow nulls. INSERT fails.
Auteur_Id is the foreign key of my parent on the table of the child
It is a bi directionnal relationship, an OF COURSE i have not forgotten to set inverse = true
When i set cascade="none" of course i got no problem but my child are not stored.
Hibernate version is 2.1.6
Here is my java code :
###############################################################################################
Auteur auteur = AuteurService.getAuteurById(formModifierAuteur.getAuteurId());
auteur.setAuteurNom(formModifierAuteur.getAuteurNom());
auteur.setAuteurPrenom(formModifierAuteur.getAuteurPrenom());
List listeBiographie = (List)httpSession.getAttribute("listeBiographie");
auteur.setBiographies(ConversionCollection.convertirListEnSet(listeBiographie));
AuteurService.updateAuteur(auteur);
Code of updateAuteur is :
-----------------------
public static void updateAuteur(Object object) throws Exception
{
log.debug("Ajout ou modification d'un objet.");
Session session = HibernateUtil.currentSession();
session.saveOrUpdate(object);
session.flush();
session.connection().commit();
log.debug("Ajout ou modification effectuée.");
HibernateUtil.closeSession();
}
###############################################################################################
Here is the parent mapping file :
###############################################################################################
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="fr.secrets.intranet.commercial.modeles.Auteur"
table="Auteur"
>
<id
name="auteurId"
type="java.lang.Integer"
column="Auteur_ID"
>
<generator class="native" />
</id>
<property
name="auteurNom"
type="java.lang.String"
column="Auteur_Nom"
length="1073741823"
/>
<property
name="auteurPrenom"
type="java.lang.String"
column="Auteur_Prenom"
length="1073741823"
/>
<!-- associations -->
<!-- bi-directional one-to-many association to Biographie -->
<set
name="biographies"
lazy="false"
inverse="true"
cascade="all"
>
<key>
<column name="Auteur_ID" />
</key>
<one-to-many
class="fr.secrets.intranet.commercial.modeles.Biographie"
/>
</set>
<!-- bi-directional many-to-many association to Article -->
<set
name="articles"
lazy="true"
table="RArticleAuteur"
>
<key>
<column name="Auteur_ID" />
</key>
<many-to-many
class="fr.secrets.intranet.commercial.modeles.Article"
>
<column name="Article_ID" />
</many-to-many>
</set>
</class>
</hibernate-mapping>
###############################################################################################
And here is the child :
###############################################################################################
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="fr.secrets.intranet.commercial.modeles.Biographie"
table="Biographie"
>
<id
name="biographieId"
type="java.lang.Integer"
column="Biographie_ID"
>
<generator class="native" />
</id>
<property
name="biographieBioFrancais"
type="java.lang.String"
column="Biographie_BioFrancais"
length="1073741823"
/>
<property
name="biographieBioAnglais"
type="java.lang.String"
column="Biographie_BioAnglais"
length="1073741823"
/>
<!-- associations -->
<!-- bi-directional many-to-one association to Auteur -->
<many-to-one
name="auteur"
class="fr.secrets.intranet.commercial.modeles.Auteur"
not-null="true"
>
<column name="Auteur_ID" />
</many-to-one>
<!-- bi-directional many-to-one association to Collection -->
<many-to-one
name="collection"
class="fr.secrets.intranet.commercial.modeles.Collection"
not-null="true"
>
<column name="Collection_ID" />
</many-to-one>
</class>
</hibernate-mapping>
###############################################################################################
Log trace is :
###############################################################################################
[2004-11-30 19:12:46,459 net.sf.hibernate.connection.DriverManagerConnectionProvider DEBUG] total checked-out connections: 0
[2004-11-30 19:12:46,459 net.sf.hibernate.connection.DriverManagerConnectionProvider DEBUG] using pooled JDBC connection, pool size: 0
[2004-11-30 19:12:46,629 net.sf.hibernate.util.JDBCExceptionReporter WARN] SQL Error: 515, SQLState: 23000
[2004-11-30 19:12:46,629 net.sf.hibernate.util.JDBCExceptionReporter ERROR] Cannot insert the value NULL into column 'Auteur_ID', table 'HetCJacques.dbo.Biographie'; column does not allow nulls. INSERT fails.
[2004-11-30 19:12:46,639 net.sf.hibernate.util.JDBCExceptionReporter WARN] SQL Error: 515, SQLState: 23000
[2004-11-30 19:12:46,639 net.sf.hibernate.util.JDBCExceptionReporter ERROR] Cannot insert the value NULL into column 'Auteur_ID', table 'HetCJacques.dbo.Biographie'; column does not allow nulls. INSERT fails.
[2004-11-30 19:12:46,639 net.sf.hibernate.util.JDBCExceptionReporter ERROR] could not insert: [fr.secrets.intranet.commercial.modeles.Biographie]
java.sql.SQLException: Cannot insert the value NULL into column 'Auteur_ID', table 'HetCJacques.dbo.Biographie'; column does not allow nulls. INSERT fails.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:366)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2048)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:1648)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:489)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:348)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:360)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:528)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:432)
at net.sf.hibernate.impl.ScheduledIdentityInsertion.execute(ScheduledIdentityInsertion.java:29)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:932)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:857)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:775)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1388)
at net.sf.hibernate.engine.Cascades$4.cascade(Cascades.java:114)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:436)
at net.sf.hibernate.engine.Cascades.cascadeCollection(Cascades.java:526)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:452)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:503)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:482)
at net.sf.hibernate.impl.SessionImpl.doUpdate(SessionImpl.java:1475)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1393)
at fr.secrets.intranet.commercial.hibernate.HibernateService.saveOrUpdateObject(HibernateService.java:71)
at fr.secrets.intranet.commercial.services.AuteurService.updateAuteur(AuteurService.java:33)
at fr.secrets.intranet.commercial.struts.actions.auteur.ActionModifierAuteur.execute(ActionModifierAuteur.java:51)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:459)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:268)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1191)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:455)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:793)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:702)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:571)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:644)
at java.lang.Thread.run(Thread.java:534)
[2004-11-30 19:12:46,659 org.apache.struts.action.RequestProcessor WARN] Unhandled Exception thrown: class net.sf.hibernate.JDBCException