-->
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: Why is it generating updates after fetching data?
PostPosted: Fri Feb 16, 2007 1:55 pm 
Newbie

Joined: Fri Feb 16, 2007 1:30 pm
Posts: 2
Hibernate version: 1.2.0b3

Code between sessionFactory.openSession() and session.close():

Name and version of the database you are using: SQL Server 2005


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="PlaceTrakTNG.Business.Placement, PlaceTrakTNG.Business" table="Placement" >
<id name="placementID" column="PlacementID" access="field" type="Int32" unsaved-value="null">
<generator class="native"></generator>
</id>
<property name="FirstName" column="FirstName" type="String" access="property" not-null="true"></property>
<property name="LastName" column="LastName" type="String" access="property" not-null="true"></property>

<many-to-one name="Coordinator" class="PlaceTrakTNG.Business.User, PlaceTrakTNG.Business" column="CoordinatorUserID" access="property" fetch="join" ></many-to-one>
<many-to-one name="Specialist" class="PlaceTrakTNG.Business.User, PlaceTrakTNG.Business" column="SpecialistUserID" access="property" fetch="join" ></many-to-one>
<many-to-one name="ServiceRep" class="PlaceTrakTNG.Business.User, PlaceTrakTNG.Business" column="ServiceRepUserID" access="property" fetch="join" ></many-to-one>
<many-to-one name="CustomerServiceRep" class="PlaceTrakTNG.Business.User, PlaceTrakTNG.Business" column="CustomerServiceRepUserID" access="property" fetch="join" ></many-to-one>
</class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="PlaceTrakTNG.Business.User, PlaceTrakTNG.Business" table="[User]" >
<id name="userID" column="UserID" type="Int32" access="field" unsaved-value="null">
<generator class="native" />
</id>
<version name="version" type="Int32" unsaved-value="null" access="field" />
<property name="LoginName" column="LoginName" type="Nullables.NHibernate.EmptyStringType, Nullables.NHibernate" access="property"></property>
<property name="Password" column="Password" type="Nullables.NHibernate.EmptyStringType, Nullables.NHibernate" access="property"></property>
<property name="FirstName" column="FirstName" type="Nullables.NHibernate.EmptyStringType, Nullables.NHibernate" access="property"></property>
<property name="LastName" column="LastName" type="Nullables.NHibernate.EmptyStringType, Nullables.NHibernate" access="property"></property>

<set name="CoordinatorPlacements" inverse="true" access="property" >
<key column="UserID" foreign-key="CoordinatorUserID"></key>
<one-to-many class="PlaceTrakTNG.Business.Placement, PlaceTrakTNG.Business" ></one-to-many>
</set>

<set name="RMPlacements" inverse="true" access="property" >
<key column="UserID" foreign-key="ServiceRepUserID"></key>
<one-to-many class="PlaceTrakTNG.Business.Placement, PlaceTrakTNG.Business" ></one-to-many>
</set>

<set name="CSRPlacements" inverse="true" access="property" >
<key column="UserID" foreign-key="CustomerServiceRepUserID"></key>
<one-to-many class="PlaceTrakTNG.Business.Placement, PlaceTrakTNG.Business" ></one-to-many>
</set>

<set name="ASPlacements" inverse="true" access="property" >
<key column="UserID" foreign-key="SpecialistUserID"></key>
<one-to-many class="PlaceTrakTNG.Business.Placement, PlaceTrakTNG.Business" ></one-to-many>
</set>

</class>

</hibernate-mapping>

When I call:

IList areaSpecialists = userDAO.GetPlacementRelatedAS();
IList csr = userDAO.GetPlacementRelatedCSR();
IList hc = userDAO.GetPlacementRelatedHC();
IList rms = userDAO.GetPlacementRelatedRM();


in my code-behind to get list of users who are related to Placement it works fine, however when I examine the log output nhibernate is generating updates after fetching the data:


007-02-16 10:20:18,320 [4136] INFO NHibernate.Loader.Loader [(null)] - select distinct u.* from [user] u join placement p on u.userID = p.CoordinatorUserID order by u.firstName, u.lastName
2007-02-16 10:20:18,320 [4136] DEBUG NHibernate.SQL [(null)] - select distinct u.* from [user] u join placement p on u.userID = p.CoordinatorUserID order by u.firstName, u.lastName
2007-02-16 10:20:18,351 [4136] DEBUG NHibernate.SQL [(null)] - UPDATE [User] SET version = @p0, LoginName = @p1, Password = @p2, FirstName = @p3, LastName = @p4, Title = @p5, Email = @p6, Phone = @p7, Fax = @p8, GroupID = @p9 WHERE UserID = @p10 AND version = @p11; @p0 = '8', @p1 = 'alove', @p2 = 'asdf ', @p3 = 'Amanda', @p4 = 'Love', @p5 = 'Account Coordinator', @p6 = '', @p7 = '', @p8 = '(5', @p9 = '21', @p10 = '10056', @p11 = '7'
2007-02-16 10:20:18,351 [4136] DEBUG NHibernate.SQL [(null)] - UPDATE [User] SET version = @p0, LoginName = @p1, Password = @p2, FirstName = @p3, LastName = @p4, Title = @p5, Email = @p6, Phone = @p7, Fax = @p8, GroupID = @p9 WHERE UserID = @p10 AND version = @p11; @p0 = '8', @p1 = 'aranly', @p2 = 'asdf ', @p3 = 'Amie', @p4 = 'Ranly', @p5 = 'Regional Sales Executive', @p6 = ', @p7 = '', @p8 = '', @p9 = '21', @p10 = '1000119', @p11 = '7'
2007-02-16 10:20:18,351 [4136] DEBUG NHibernate.SQL [(null)] - UPDATE [User] SET version = @p0, LoginName = @p1, Password = @p2, FirstName = @p3, LastName = @p4, Title = @p5, Email = @p6, Phone = @p7, Fax = @p8, GroupID = @p9 WHERE UserID = @p10 AND version = @p11; @p0 = '8', @p1 = '', @p2 = ' ', @p3 = 'Anne', @p4 = 'Parkhurst', @p5 = 'Placement Coordinator', @p6 = '', @p7 = '(800) ', @p8 = '', @p9 = '21', @p10 = '20079', @p11 = '7'


Anyone have any ideas why NHibernate is updating after fetching? I'm not doing _anything_ to modify the model objects, just fetching them to bind to dropdownlists. I even commented the databinding, and they are still being updated...

Also, this issue was also mentioned by someone else in post: http://forum.hibernate.org/viewtopic.ph ... date+fetch


Thanks,

Rich C.


Top
 Profile  
 
 Post subject: Found the problem
PostPosted: Fri Feb 16, 2007 7:55 pm 
Newbie

Joined: Fri Feb 16, 2007 1:30 pm
Posts: 2
Figured out what was causing the User objects to get updated.

I had set the 'LoginName' get property to return loginName.Trim() as the db type was set to char(20) and I was getting whitespace back... When NHibernate loaded the User again and compared values, the LoginName was marked dirty and updated...

I fixed the database datatype, and all is well now...


found this problem described in this post as well:
http://forum.hibernate.org/viewtopic.ph ... ght=update


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.