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.  [ 9 posts ] 
Author Message
 Post subject: hibernate save unmodified object
PostPosted: Fri Oct 20, 2006 8:57 am 
Newbie

Joined: Fri Oct 20, 2006 8:39 am
Posts: 4
Hi,

When I execute this code, hibernate creates in the db the new instance of PrestationPeriodiqueReelle (it's fine ....) but also update the PrestationPeriodique object and all the objects graph related to the parent.

ITransaction aTransaction = session.BeginTransaction();

PrestationPeriodique p = (PrestationPeriodique)session.Load(typeof(PrestationPeriodique), 1);

PrestationPeriodiqueReelle pr = new PrestationPeriodiqueReelle();
pr.Dossier = p.Dossier;
pr.Parent = p.Parent;
pr.OffreDetail = p.OffreDetail;
pr.Agent = p.Agent;
pr.DateRealisation = DateTime.Now;
pr.DateFin = DateTime.Now.AddMonths(1);
pr.Objet = p.Objet;

p.PrestationsReelles.Add(pr);
pr.PrestationPeriodique = p;

session.SaveOrUpdate(p);

aTransaction.commit();

I thought that Hibernate only saves modified object.

Perhaps I haven't configured rightly mapping files.

Thanks for your help


Top
 Profile  
 
 Post subject: Re: hibernate save unmodified object
PostPosted: Fri Oct 20, 2006 9:25 am 
Beginner
Beginner

Joined: Wed Aug 03, 2005 8:06 am
Posts: 40
Location: Netherlands
sra wrote:
Perhaps I haven't configured rightly mapping files.


Hard to tell if we can't see your mappings...
Please show them or otherwise try session.Save(pr);


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 20, 2006 10:35 am 
Newbie

Joined: Fri Oct 20, 2006 8:39 am
Posts: 4
Here are the mapping files. When you update an object, only the modified objects are saved or all ?



Mapping of the parent object

Code:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="PhenixPlus.model.client.dossier.prestation.PrestationPeriodique, PhenixPlus" table="PrestationPeriodique" >
      <id name="PrestationID" column="ID" type="Int32" unsaved-value="0">
        <generator class="identity" />   
      </id>
      <many-to-one column="DossierId" name="Dossier" class="PhenixPlus.model.client.dossier.IDossier, PhenixPlus"/>
      <many-to-one column="ParentId" name="Parent" class="PhenixPlus.model.client.dossier.prestation.DossierRepertoire, PhenixPlus"/>
      <many-to-one column="OffreDetailId" name="OffreDetail" class="PhenixPlus.model.client.OffreDetail, PhenixPlus"/>
      <many-to-one column="AgentId" name="Agent" class="PhenixPlus.model.personel.Utilisateur, PhenixPlus"/>
      <many-to-one column="ObjetID" name="Objet" cascade="all"  class="PhenixPlus.model.catalogue.Objet, PhenixPlus"/>
      <property name="Statut" column="Statut" type="Int32" length="4" />
      <property name="DateDepart" column="DateDepart" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" />
      <property name="PeriodeDB" column="Periode" type="String"/>
      <property name="Frequence" column="Frequence" type="Int32" length="4" />
      <property name="DisplayOrder" column="DisplayOrder" type="Int32" length="4" />
      <bag name="PrestationsReelles" cascade="all" lazy="true" inverse="true">
         <key column="PeriodiqueID"/>
         <one-to-many class="PhenixPlus.model.client.dossier.prestation.PrestationPeriodiqueReelle, PhenixPlus"/>
      </bag>
   </class>
</hibernate-mapping>



Mapping file of the child object

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="PhenixPlus.model.client.dossier.prestation.PrestationPeriodiqueReelle, PhenixPlus" table="Prestation" >
      <id name="PrestationID" column="ID" type="Int32" unsaved-value="0">
        <generator class="identity" />
      </id>
      <discriminator column="Type" type="String" />
      <many-to-one column="PeriodiqueID" name="PrestationPeriodique" class="PhenixPlus.model.client.dossier.prestation.PrestationPeriodique, PhenixPlus"/>
      <many-to-one column="DossierId" name="Dossier" class="PhenixPlus.model.client.dossier.IDossier, PhenixPlus"/>
      <many-to-one column="OffreDetailId" name="OffreDetail" class="PhenixPlus.model.client.OffreDetail, PhenixPlus"/>
      <many-to-one column="AgentId" name="Agent" class="PhenixPlus.model.personel.Utilisateur, PhenixPlus"/>
      <many-to-one column="ObjetID" name="Objet" cascade="all"  class="PhenixPlus.model.catalogue.Objet, PhenixPlus"/>
      <property name="DateRealisation" column="DateRealisation" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" />
      <property name="DateFin" column="DateFin" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" />
      <property name="HeurePrestee" formula="(select sum(p.Heure) from Pointage p where p.PrestationID= ID)"/>
      <property name="DisplayOrder" column="DisplayOrder" type="Int32" length="4" />
      <property name="Statut" column="Statut" type="Int32" length="4" />
   </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 22, 2006 2:53 pm 
Newbie

Joined: Fri Oct 20, 2006 8:39 am
Posts: 4
Hi,

I have found what's going wrog.

It's not related to mappings.

The problem was that I use enum for some fields. It seems that when loading the object, Hibernate cast an integer to the enum. This operation modify the state of the object.

That's why some extra updates were made.

Workaround.

Define a private property that encapsulate the data from the db and define a public property that casts the integer into the enum.

Thanks fo help.

Serge


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 22, 2006 4:21 pm 
Beginner
Beginner

Joined: Wed Aug 03, 2005 8:06 am
Posts: 40
Location: Netherlands
You can also supply your enum as the datatype of the field that is an enum, (type="namespace.enumtype, assemblyname")


Top
 Profile  
 
 Post subject: Re: hibernate save unmodified object
PostPosted: Fri Jul 24, 2009 2:22 pm 
Newbie

Joined: Fri Jul 24, 2009 2:19 pm
Posts: 1
very interesting post! thanks a lot for sharing it with us..


commission de surendettement - commission de surendettement, vous pouvez demander un dossier de surendettement.


Top
 Profile  
 
 Post subject: Re: hibernate save unmodified object
PostPosted: Wed Aug 05, 2009 10:53 pm 
Newbie

Joined: Wed Aug 05, 2009 10:52 pm
Posts: 1
this is interesting.. thanks so much for sharing!


plan solution commission de surendettement - commission de surendettement, vous pouvez demander un dossier de surendettement.plan solution commission de surendettement


Top
 Profile  
 
 Post subject: Re: hibernate save unmodified object
PostPosted: Tue Aug 18, 2009 4:23 am 
Newbie

Joined: Tue Aug 18, 2009 3:42 am
Posts: 2
It seems that when loading the object
proprietaire simulation rachat credit immobilier consommation - demander un rachat de crédit, faites une simulation rachat de credit en ligne.proprietaire simulation rachat credit immobilier consommation


Top
 Profile  
 
 Post subject: Re: hibernate save unmodified object
PostPosted: Tue Aug 25, 2009 2:44 am 
Newbie

Joined: Tue Aug 25, 2009 2:41 am
Posts: 1
Thanks for sharing infor here


calcul pret assurance simulation taux emprunt immobilier - Taux emprunt immobilier. Comparez les offres d’emprunt immobilier, simulation emprunt immobilier, taux emprunt immobiliercalcul pret assurance simulation taux emprunt immobilier


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