Send update queries even when no change made.

12 views
Skip to first unread message

Mark Jensen

unread,
Jan 29, 2012, 11:06:35 AM1/29/12
to Castle Project Users
Hi

If i fetch something from the database, dont make any changes and then
save my entity. I would expect that no UPDATE statements gets called.
How this doesn't seem to be the case.

I found this post from a guy you had the same problem, but only with
NH

http://ahmedshuhel.blogspot.com/2011/01/nhibernate-send-update-queries-even.html

And i have tried to add "Not-Null=true" to all the attributes on my
entity, but not luck, I stille get an UPDATE statement.

Is there something wrong with AR or am i missing something?

br
Mark

Mauricio Scheffer

unread,
Jan 29, 2012, 7:03:31 PM1/29/12
to castle-pro...@googlegroups.com
Yes, as the author of the blog post you mentioned says, this is likely the consequence of a mapping error. 
I don't think ActiveRecord has anything to do here... I'd try running a test to find mapping issues. Here's a newer version of Fabio's "Ghostbusters":  http://joseoncode.com/2010/02/05/nhibernate-ghostbuster-version-1-1/ 
If that doesn't work, try isolating the issue in a stand-alone test so we can diagnose the problem.

--
Mauricio


Mark

--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.


Eric Tarasoff

unread,
Jan 29, 2012, 11:36:07 AM1/29/12
to Castle Project Users

I had a similar problem. Not sure if this applies here but with NULL
columns in the database (excluding nvarchar/string), making the
properties on the entity nullable types (ie int? or DateTime?)
resolved the unexpected update.

On Jan 29, 8:06 am, Mark Jensen <don...@gmail.com> wrote:
> Hi
>
> If i fetch something from the database, dont make any changes and then
> save my entity. I would expect that no UPDATE statements gets called.
> How this doesn't seem to be the case.
>
> I found this post from a guy you had the same problem, but only with
> NH
>
> http://ahmedshuhel.blogspot.com/2011/01/nhibernate-send-update-querie...

Mark Jensen

unread,
Feb 6, 2012, 1:25:31 PM2/6/12
to Castle Project Users

Here is a very simple AR entity

[ActiveRecord("Organizations", DynamicUpdate = true)]
    public class Organization : ActiveRecordBase<Organization>
    {
        private Organization(){}

        [PrimaryKey(PrimaryKeyType.GuidComb, "Id")]
        public Guid Id { get; set; }

        [Property("Name", NotNull = true, Length = 50)]
        public string Name { get; set; }
}

DB Scheme

Id uniqueidentifier NotNull
Name nvarchar(50) NotNull

Here is what happens when i run my unit test (im using Log4Net)

SELECT organizati0_.Id as Id8_0_, organizati0_.Name as Name8_0_ FROM
Organizations organizati0_ WHERE organizati0_.Id=@p0;@p0 =
54131a04-1e04-4274-ad3c-9fb401682ceb [Type: Guid (0)]
UPDATE Organizations SET Name = @p0 WHERE Id = @p1;@p0 = 'test company
1' [Type: String (50)], @p1 = 54131a04-1e04-4274-ad3c-9fb401682ceb
[Type: Guid (0)]

So as you can see, its pretty straight forward..



On Jan 30, 1:03 am, Mauricio Scheffer <mauricioschef...@gmail.com>
wrote:
> Yes, as the author of the blog post you mentioned says, this is likely the
> consequence of a mapping error.
> I don't think ActiveRecord has anything to do here... I'd try running a
> test to find mapping issues. Here's a newer version of Fabio's
> "Ghostbusters":http://joseoncode.com/2010/02/05/nhibernate-ghostbuster-version-1-1/
> If that doesn't work, try isolating the issue in a stand-alone test so we
> can diagnose the problem.
>
> --
> Mauricio
>
>
>
>
>
>
>
> On Sun, Jan 29, 2012 at 1:06 PM, Mark Jensen <don...@gmail.com> wrote:
> > Hi
>
> > If i fetch something from the database, dont make any changes and then
> > save my entity. I would expect that no UPDATE statements gets called.
> > How this doesn't seem to be the case.
>
> > I found this post from a guy you had the same problem, but only with
> > NH
>
> >http://ahmedshuhel.blogspot.com/2011/01/nhibernate-send-update-querie...

Mark Jensen

unread,
Feb 6, 2012, 2:16:52 PM2/6/12
to Castle Project Users
And... when I use the GhostBuster you link too, i get the following
result

s--------Core.Domain.Models.Organization
e--------Core.Domain.Models.Organization

Not really sure what to make of that


On Jan 30, 1:03 am, Mauricio Scheffer <mauricioschef...@gmail.com>
wrote:
> Yes, as the author of the blog post you mentioned says, this is likely the
> consequence of a mapping error.
> I don't think ActiveRecord has anything to do here... I'd try running a
> test to find mapping issues. Here's a newer version of Fabio's
> "Ghostbusters":http://joseoncode.com/2010/02/05/nhibernate-ghostbuster-version-1-1/
> If that doesn't work, try isolating the issue in a stand-alone test so we
> can diagnose the problem.
>
> --
> Mauricio
>
>
>
>
>
>
>
> On Sun, Jan 29, 2012 at 1:06 PM, Mark Jensen <don...@gmail.com> wrote:
> > Hi
>
> > If i fetch something from the database, dont make any changes and then
> > save my entity. I would expect that no UPDATE statements gets called.
> > How this doesn't seem to be the case.
>
> > I found this post from a guy you had the same problem, but only with
> > NH
>
> >http://ahmedshuhel.blogspot.com/2011/01/nhibernate-send-update-querie...

Mark Jensen

unread,
Feb 20, 2012, 12:39:07 PM2/20/12
to Castle Project Users
bump..

Mark Jensen

unread,
Feb 28, 2012, 11:23:00 AM2/28/12
to Castle Project Users
hmm.. it seems like i need to do this, to prevent it from hitting the
database every time when no changes are made.

http://www.castleproject.org/activerecord/documentation/trunk/usersguide/web.html


...and I have also added isWeb="true".. Not sure if that one makes any
difference

http://www.castleproject.org/activerecord/documentation/trunk/manual/xmlconfigref.html
Reply all
Reply to author
Forward
0 new messages