-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Update instead of insert, why??
PostPosted: Fri Jul 08, 2005 6:34 am 
Newbie

Joined: Fri Jul 08, 2005 6:23 am
Posts: 5
Hi H8 gurus, I'm a new user, this is my situation.

Hibernate version:
2.1.7

Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="it.ras.nsc.struts.hibernate">
<class name="KpiH" table="kpi">
<id name="prg_contatore" column="prg_contatore">
<generator class="identity"/>
</id>
<property name="id_sessione" column="id_sessione"/>
<set name="dettagliokpi" cascade = "save-update" lazy="true" inverse="true">
<key column="id_sessione"/>
<one-to-many class="DettaglioKpiH"/>
</set>
<property name="id_versione_browser" column="id_versione_browser"/>
<property name="referrer" column="referrer"/>
<property name="query_string" column="query_string"/>
<property name="path_info" column="path_info"/>
<property name="remote_address" column="remote_address"/>
<property name="remote_host" column="remote_host"/>
<property name="durata_connessione" column="durata_connessione"/>
<property name="data_inizio_sessione" column="data_inizio_sessione"/>
<property name="pagine_visitate" column="pagine_visitate"/>
<property name="UserId" column="UserId"/>
<property name="tipo_utente" column="tipo_utente"/>
<property name="cod_comp" column="cod_comp"/>
</class>
</hibernate-mapping>


Second one:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="it.ras.nsc.struts.hibernate">
<class name="DettaglioKpiH" table="dettagliokpi">

<id name="id" column="id">
<generator class="identity"/>
</id>
<many-to-one name="kpi"
column="id_sessione"
class="KpiH"
not-null="true"/>
<property name="ora_inizio" column="ora_inizio"/>
<property name="contatore" column="contatore"/>
<property name="durata" column="durata"/>
<property name="area_logica" column="area_logica"/>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
kpiH = new KpiH();
dettaglioH = new DettaglioKpiH();

dettaglioH.setKpi(kpiH);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
dettaglioH.setArea_logica("fake area");
dettaglioH.setDurata(150);
dettaglioH.setOra_inizio(sdf.format(new Date()));

kpiH.setId_sessione(sessionManager.getSid());
kpiH.setPrg_contatore(dao.getLastRecordId());
kpiH.setPagine_visitate(pagineVisitate);
String dataInzioSessione = kpiH.getData_inizio_sessione();
kpiH.setDurata_connessione(new Long(durataSessione).intValue());
kpiH.add(dettaglioH);

Full stack trace of any exception that occurs:
12:21:05,125 ERROR [SessionImpl] 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.persister.EntityPersister.update(EntityPersister.java:689)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:642)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2414)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2368)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
at org.springframework.orm.hibernate.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:210)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:315)
at org.springframework.orm.hibernate.HibernateTemplate.save(HibernateTemplate.java:493)
at it.ras.nsc.struts.dao.KpiDAO.saveStatsData(KpiDAO.java:50)
at it.ras.nsc.struts.beans.StatService.saveData(StatService.java:142)
at it.ras.nsc.struts.actions.Logout.execute(Logout.java:46)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
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.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
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.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:66)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:158)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540)
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.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
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:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)

Name and version of the database you are using:
SQLServer
The generated SQL (show_sql=true):
12:20:50,203 INFO [STDOUT] Hibernate: insert into kpi (id_sessione, id_versione_browser, referrer, query_string, path_info, remote_address, remote_host, durata_connessione, data_inizio_sessione, pagine_visitate, UserId, tipo_utente, cod_comp) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) select SCOPE_IDENTITY()
12:20:50,343 INFO [STDOUT] Hibernate: update dettagliokpi set id_sessione=?, ora_inizio=?, contatore=?, durata=?, area_logica=? where id=?



It seems to correctly insert one row into the MASTER table (kpi), then to make an update in the SLAVE table (dettagliokpi) of a row that not exists yet. I would like to insert the row in the slave table, not update.
Of course I have done some mistake in mapping files or in the java code but I cannot find it out :(

Any helps would be very very appreciated ;)

Salud

Max


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 8:47 am 
Senior
Senior

Joined: Thu May 12, 2005 11:40 pm
Posts: 125
Location: Canada
http://www.hibernate.org/116.html#A38


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.