-->
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.  [ 5 posts ] 
Author Message
 Post subject: update instead of save
PostPosted: Wed Dec 17, 2003 6:27 am 
Regular
Regular

Joined: Thu Nov 20, 2003 10:44 am
Posts: 58
Location: Paris, France
I try to save an object but Hibernate try to update a field on a one-to-one association, therefore I have an exception because the data doesn't exist.


Code:
Hibernate: insert into SIREN (APPARTENANCE_DGE, PK_NUM_SIREN) values (?, ?)
Hibernate: insert into ADHERENT (ADR_MAIL, CIVILITE, DATE_CREATION, DATE_FIN_VALIDITE, NOM, NUM_TEL, PRENOM, ID_RENOUVELLEMENT, PK_NUM_ADHERENT) values (?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into TRACE (DATE_EVT, DATE_PURGE_EVT, DETAIL_EVT_2, DETAIL_EVT_3, DETAIL_EVT_1, ID_USAGER, ESERVICE, ID_AGENT, ID_APPLICATIF, LIB_SIREN_USAGER, LISTE_IMPOT, NOM_AGENT, NOM_USAGER, NOM_SERVICE, NUM_CERTIFICAT_USAGER, NUM_FORMULAIRE, NUM_SAGES, NUM_SAGES_AGENT, NUM_SIREN_USAGER, PRENOM_AGENT, PRENOM_USAGER, ROLE_USAGER, SIREN_ACTION, TYPE_EVT, PK_TRACE) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: update SIREN_APPARTENANCE set SIREN=?, ETRANGER=? where PK_NUM_ADHERENT=?
- Could not synchronize database state with session
net.sf.hibernate.HibernateException: SQL update or deletion failed (row not found)
   at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
   at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:722)
   at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:675)
   at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:51)
   at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2362)
   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2317)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2258)
   at fr.gouv.finances.dgi.opale.technique.util.SessionHibernate.endTransaction(SessionHibernate.java:116)
   at fr.gouv.finances.dgi.opale.inscription.services.AdherentServiceImpl.inscrireAdherent(AdherentServiceImpl.java:121)
   at TestCnxDB.main(TestCnxDB.java:174)
- Erreur hibernate


with the following mapping :
Code:
<hibernate-mapping>
   <class name="fr.gouv.finances.dgi.opale.commun.transverse.persistent.AdherentPersistent" table="ADHERENT">
      <id name="numAdherent" column="PK_NUM_ADHERENT">
         <generator class="assigned"/>
      </id>
      <property name="adrMailAdherent" column="ADR_MAIL" not-null="true"/>
      <property name="civiliteAdherent" column="CIVILITE" not-null="true"/>
      <property name="dateCreationAdherent" column="DATE_CREATION" not-null="true" type="date"/>
      <property name="dateFinValiditeIdRenouvellement" column="DATE_FIN_VALIDITE" type="date" not-null="false"/>
      <property name="nomAdherent" column="NOM" not-null="true"/>
      <property name="numTelAdherent" column="NUM_TEL" not-null="false"/>
      <property name="prenomAdherent" column="PRENOM" not-null="true"/>
      <one-to-one name="sirenAppartenance" class="fr.gouv.finances.dgi.opale.commun.transverse.persistent.SirenAppartenancePersistent" cascade="save-update" constrained="false"/>
      <property name="idRenouvellement" column="ID_RENOUVELLEMENT" not-null="false"/>
      <one-to-one name="adresse" class="fr.gouv.finances.dgi.opale.commun.transverse.persistent.AdressePersistent" cascade="save-update" constrained="false"/>
      <one-to-one name="certificat" class="fr.gouv.finances.dgi.opale.commun.transverse.persistent.CertificatPersistent" cascade="save-update" constrained="false"/>
      <set name="listeReponseQuestionConfianceAdherent" lazy="true" inverse="true" cascade="save-update">
         <key column="FK_NUM_ADHERENT"/>
         <one-to-many class="fr.gouv.finances.dgi.opale.commun.transverse.persistent.ReponseQuestionConfianceAdherentPersistent"/>
      </set>
   </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 7:14 am 
Regular
Regular

Joined: Thu Nov 20, 2003 10:44 am
Posts: 58
Location: Paris, France
No idea ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 8:09 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
gbonnard wrote:
No idea ?

Yes.
Show your SirenAppartenancePersistent mapping. You did something wrong with <id unsaved-value>. If you have an assigned id or a composite one, please read the faqs

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 8:16 am 
Regular
Regular

Joined: Thu Nov 20, 2003 10:44 am
Posts: 58
Location: Paris, France
Emmanuel,
I do not understand how it works.
What I want to do is very simple : save the data when I use save and update it when I use update !!!!

BUT :
--> if I put unsaved-value="any" Hibernate insert each time (so I have PK constraints error when I update)
--> if I put unsaved-value="null" Hibernate update each time (so i have a no row fund error when I save)

Could please tell me what I should do ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 9:58 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Cascaded save or update are always saveOrUpdate.
You have several solutions (look at the docs for more infos) :
- do not cascade
- use an interceptor
- use version or timestamp unsaved-value (2.1 feature)

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.