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: Query.List makes my objects Dirty, why?
PostPosted: Wed Sep 19, 2007 3:09 am 
Newbie

Joined: Wed Sep 19, 2007 2:59 am
Posts: 14
Hi
Im doing two IQuery in the same method, and when i call List on the second ( queryVersions.List() ), the object becames dirty. I quite dont see why, maybe its obvious but please tell me :) Caus i dont get it.

Code:
IList<DocumentDto> list = new List<DocumentDto>();

            string hql = "from DocumentVersion as v where v.Document.Person.Id = :personId "
            + "and v.IsLatest = :isLatest order by v.UpdatedDateAndTime asc";

            IQuery query = Session.CreateQuery(hql);
            query.SetParameter("personId", personId);
            query.SetParameter("isLatest", true);

            IList versions = query.List();

            foreach (DocumentVersion version in versions)
            {
                list.Add(DocumentTransformation.TransformToDocumentDto(version));

                string hqlVersions = "from DocumentVersion as v where v.Document.Person.Id = :personId "
                   + "and v.IsLatest = :isLatest and v.Document.Id = :latestId order by v.UpdatedDateAndTime ASC";
                IQuery queryVersions = Session.CreateQuery(hqlVersions);
                queryVersions.SetParameter("personId", personId);
                queryVersions.SetParameter("isLatest", false);
                queryVersions.SetParameter("latestId", version.Id);
                IList versionsOther = queryVersions.List();
                //After  queryVersions.List() the objects becomes dirty

                foreach (DocumentVersion c in versionsOther)
                {
                    list.Add(DocumentTransformation.TransformToDocumentDto(c));
                }
            }


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 20, 2007 2:33 am 
Newbie

Joined: Wed Sep 19, 2007 2:59 am
Posts: 14
If i do this

Code:
foreach (DocumentVersion version in  query.List())
{
}


its getting dirty directly[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 20, 2007 7:57 am 
Regular
Regular

Joined: Thu Nov 23, 2006 10:29 am
Posts: 106
Location: Belgium
Hello,

I'm not sure if this might help, but I had also problems with objects that were constantly marked as being dirty even when I didn't change anything about them.

The reason turned out to be the fact that in some of my properties, my getter actually initialized the property. To NHibernate, when it's checking for modifs, that means the object is 'dirty' (because the property returns a different value than it was assigned to when the object was created).

Maybe you've got the same problem somewhere in your object's code ?

_________________
Please rate this post if it helped.

X.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 23, 2007 12:56 pm 
Regular
Regular

Joined: Wed Apr 25, 2007 4:18 am
Posts: 51
Location: Belarus, Gomel
Hi Erik!

You may have problem with DateTime fields - if database allow null values. You have to use Nullable<DateTime>, or add "not null" constraint and change all null values to some reasonable value.

_________________
WBR, Igor


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.