-->
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.  [ 4 posts ] 
Author Message
 Post subject: Persists wrong object
PostPosted: Thu Jun 26, 2008 8:29 am 
Beginner
Beginner

Joined: Mon Jan 14, 2008 10:58 am
Posts: 24
Hi,
I have some problems!

I'm saving an object to database. But when I save it, the database also updates a completly different object!
Mapping file of the saving object
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
   <class name="Entities.Log, Entities" table="Logs">
      <id name="Id" column="LogID" type="int" unsaved-value="0">
         <generator class="identity" />
      </id>
      <property name="Category" column="Category" type="String" />
      <property name="Source" column="Source" type="String"/>
      <property name="Description" column="Description" type="String"/>
      <property name="User" column="[User]" type="String"/>
      <property name="Ip" column="Ip" type="String"/>
      <property name="CreateDate" column="CreateDate" type="DateTime" />
      <property name="SiteName" column="SiteName" type="String"/>
   </class>
</hibernate-mapping>


Code for saving the object
Code:
Entities.Log log = new Entities.Log();
log.Category = "LOGIN";
log.Source = "";
log.Description = "Loggade in";
log.SiteName = site.Name;
log.User = user.Profile.FirstName + " " + user.Profile.LastName;
log.Ip = Request.UserHostAddress;
log.CreateDate = DateTime.Now;
LogDao.Save(log);


As you see, the map has no relations to another object.
But when I save the log, the database also updates the object called 'Site' (and with some strange values!).

How can this be?
Does NHibernate saves all objects that are in use (or how I should explain)?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 26, 2008 9:07 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Hibernate saves all objects that are in the session you use for saving the log. This is done when the session is flushed, which happens when you make an explicit call for it or due to internal processing.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 26, 2008 9:19 am 
Beginner
Beginner

Joined: Mon Jan 14, 2008 10:58 am
Posts: 24
I see. Is it possible to change that?
I just want the the typed object to be saved, in this case log. Nothing else!
I dont see any reason for specifying it like LogDao.Save(log) if NHibernate still saves all objects!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 26, 2008 9:25 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
It depends on how you handle your sessions . If you want to make sure, that only this object is persisted, just use a new session for it or clear the existing one before.

_________________
--Wolfgang


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