Hi,
i have a problem with one-to-many relation.
I always have to store first the child object,
if not do that and try to store the parent with
the child without explicit store the child it
throws a Exception.
Which says SQL insert, update or delete failed (row not found).
Is that not possible that i can store a relation as whole Object,
and the hibernate resolves where he should put the parent and where the
childs.
I will put below my Configuration.xml and the code snip af my store.
<hibernate-mapping>
<class name="net.Schema.enterprise.test.Auftrag" table="Schema.Auftrag">
<id name="auftragnr" column="auftragnr" type="int">
<generator class="sequence">
<param name="sequence">Schema.Auftrag_Seq</param>
</generator>
</id>
<property name="auftragdatum"/>
<property name="auftragtermin"/>
.
..
<set name="auftragattribute" table="Schema.Auftragattribut">
<key column="auftragnr"/>
<one-to-many class="net.Schema.enterprise.test.Auftragattribut"/>
</set>
</class>
<class name="net.Schema.enterprise.test.Auftragattribut" table="Schema.Auftragattribut">
<id name="auftragnr" column="auftragnr" type="int">
<generator class="assigned"/>
</id>
<property name="attributnr"/>
<property name="attribut"/>
.
..
</class>
</hibernate-mapping>
And the save call SNIP.
net.sf.hibernate.Session hiberSess = HibernateUtil.currentSession();
Transaction tx = null;
try{
tx = hiberSess.beginTransaction();
Auftrag auft = new Auftrag();
auft.setAuftragdatum(new Timestamp(System.currentTimeMillis()));
auft.setAuftragtermin(new Date(System.currentTimeMillis()));
.....
Set set = new HashSet();
Auftragattribut att = new Auftragattribut();
att.setExtauftragnr("Ext AuftNR");
att.setAttribut(25);
......
hiberSess.save(att); // ---------------> Without this call it throws the Exception below
set.add(att);
auft.setAuftragattribute(set);
hiberSess.save(auft);
tx.commit();
}catch(HibernateException e)
{
e.printStackTrace();
out.println(e.getMessage());
}
HibernateUtil.closeSession();
Can anyone Help. I hope the description is detailed enough.
Taner.
Hibernate: values nextval for Schema.Auftrag_Seq
Hibernate: insert into Schema.Auftrag (auftragdatum, auftragtermin, auftragstatus, auftraggebernr, extauftragnr, extprojektnr, be
eichnung, vertragspartner, bereitstellungsart, geaendert, geaendert_durch, auftragnr) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: update Schema.Auftragattribut set auftragnr=? where auftragnr=?
24.03.2004 16:12:02 net.sf.hibernate.impl.SessionImpl execute
SCHWERWIEGEND: Could not synchronize database state with session
net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
at net.sf.hibernate.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:538)
at net.sf.hibernate.impl.ScheduledCollectionRecreate.execute(ScheduledCollectionRecreate.java:23)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2382)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2339)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2204)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at org.apache.jsp.hibernate_jsp._jspService(hibernate_jsp.java:89)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
|