Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 68857 invoked from network); 19 May 2008 02:34:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 19 May 2008 02:34:46 -0000 Received: (qmail 80507 invoked by uid 500); 19 May 2008 02:34:45 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 80489 invoked by uid 500); 19 May 2008 02:34:45 -0000 Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-java@ibatis.apache.org Delivered-To: mailing list user-java@ibatis.apache.org Received: (qmail 80435 invoked by uid 99); 19 May 2008 02:34:45 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 18 May 2008 19:34:45 -0700 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of nathan.maves@gmail.com designates 209.85.128.190 as permitted sender) Received: from [209.85.128.190] (HELO fk-out-0910.google.com) (209.85.128.190) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 May 2008 02:33:59 +0000 Received: by fk-out-0910.google.com with SMTP id b27so1594881fka.0 for ; Sun, 18 May 2008 19:34:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; bh=FovQdCVUcE/O6lJW2AEICUAcgJfDiJSuGOR8xuclkYs=; b=v43Vc6RGT2Su180SOKmB+EAgkjrkwkCmnuzCIvzM64JUi4Vw/GKAr+Ft1A+mNdUk12F9NVEMXO7xIw99dXI+MicBR4x4Er8AefdjfYftgVHrxjedQ1y5ZCKexP7Ii0QLFxlQy3BGpszy36D8kKf3HXA2Xsq/rmxHkXjU7p1Y4PY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=Ax6jaRGeIuZrRCnQuR4jyBWiSyB+fKDHLiSnKvkJmCu5TVs3seh8ITBSCjuvMwBoxWSpdBz4oD4kpEjX6XjkAbvQIRsrWD3H1vwpA7CmPR/0IHZBarPsWMgwxLREFyrUklx8PrAn7R+MYwcU8XL7twbH4gVQPofue8atgZ2u0Ug= Received: by 10.150.50.3 with SMTP id x3mr5838289ybx.28.1211164451820; Sun, 18 May 2008 19:34:11 -0700 (PDT) Received: by 10.150.158.4 with HTTP; Sun, 18 May 2008 19:34:11 -0700 (PDT) Message-ID: <2f55db670805181934g4691f379qe8c869e28cd348dd@mail.gmail.com> Date: Sun, 18 May 2008 20:34:11 -0600 From: "Nathan Maves" To: user-java@ibatis.apache.org, joshjdevl@gmail.com Subject: Re: Dynamic queries w/o using tags in sql? In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_13650_8674818.1211164451820" References: <16178eb10805131352qef49247n1c5f22ec7f3d3f70@mail.gmail.com> <16178eb10805131353m307df86euce912c2daa1ab8dc@mail.gmail.com> <16178eb10805131425g2799881dq694db969e328ee8d@mail.gmail.com> <16178eb10805131455i603180cah893e36bdf38cf8c3@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_13650_8674818.1211164451820 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline Josh, One little point... With your approach using dynamic tags you would never be able to set a column to null, which is a very real business case. Nathan On Tue, May 13, 2008 at 4:11 PM, Josh Joy wrote: > I guess I'll just look into this further then...I think I have a decent > enough understanding of concurrency...I'm just of the mood to let the > database handle the concurrency issues for me as much as possible rather > bringing it to the java object side... > > Going back to the original question...it seems that the answer is > no...there is no other way to dynamically generate sql for updates for > ibatis other than specifying the tag in sqll > > (also it's not a business exception if the business allows different people > to update only certain fields....) > > Thanks for info, > Josh > > > On Tue, May 13, 2008 at 4:55 PM, Clinton Begin > wrote: > >> Josh... >> >> I think you really need to look into this further, as you have a >> fundamental misunderstanding of concurrency issues and databases. >> >> * Separating the updates at the column level will NOT solve any >> concurrency problem >> * Concurrency issues are solved using either an optimistic or >> pessimistic locking model at the row level >> >> I recommend optimistic for most systems. >> >> Table Josh >> id >> name >> weburl >> timestamp >> >> update josh set ..., timestamp = now() where id = ? and timestamp = ? >> >> If the timestamps don't match, it's not simply a technical problem of >> reloading the object. You have to tell the user what happened... it's >> a business exception. What if the user would have changed the name >> differently if the URL was different or vice versa? >> >> Pessimistic locking would lock the record so that it could not be >> updated (and in some cases not even read) until it's unlocked. It's >> rare to need this type of locking in most business applications. >> >> This is a pretty core concept in database programming that you should >> understand before using iBATIS, Hibernate or even just JDBC. One book >> I can recommend is Java Transaction Processing (Mark Little), page 11 >> - 12. >> >> Any other book recommendations from anyone else? >> >> Cheers, >> Clinton >> >> On Tue, May 13, 2008 at 3:36 PM, Josh Joy wrote: >> > >> > Table Josh >> > id >> > name >> > weburl >> > >> > If one user wants to update the name, and another user wants to update >> the >> > weburl...how to avoid concurrency issues if I have to do a reload of the >> > entire object? >> > Please let me know how to configure Ibatis to handle state concurrency >> > issues if I have to fetch the entire object... >> > >> > >> > Thanks, >> > Josh >> > >> > >> > >> > >> > On Tue, May 13, 2008 at 4:25 PM, Clinton Begin > > >> > wrote: >> > > So is it completely out of the question to just load up the whole >> > > object and save the whole object? Why do you ever need any >> > > conditionals or partial updates at all? The only reason is >> > > performance (and even that really depends on the details). >> > > >> > > I don't see the problem here... :-/ >> > > >> > > Clinton >> > > >> > > >> > > >> > > >> > > On Tue, May 13, 2008 at 3:11 PM, Josh Joy >> wrote: >> > > > Thanks Clinton for your reply. >> > > > >> > > > Just to clarify...I'm not looking for any performance >> > optimizations...when I >> > > > say best practices I'm referring to dynamically choosing which >> fields to >> > > > update... >> > > > >> > > > it comes down strictly to simplicity and readability...I don't see a >> > reason >> > > > to fetch the latest entries for a row just so I can do an update >> (and >> > how >> > > > can I possibly guarantee it's the latest entry) nor do I see a >> reason to >> > > > write multiple update statements or an if statement laden sql for >> all >> > the >> > > > possible update situations that can occur... >> > > > >> > > > I'll start poking around the api to see if I can wrap something up >> for >> > my >> > > > needs for now I guess... (unless anyone has any other suggestions, >> code >> > > > snippets, or patches to share...) >> > > > >> > > > Thanks, >> > > > Josh >> > > > >> > > > >> > > > >> > > > On Tue, May 13, 2008 at 3:53 PM, Clinton Begin >> > >> > > > wrote: >> > > > > Wow, I managed to lay down 3 or 4 run-on sentences in a row >> there... >> > > > > Sorry Mr. McMillan... >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > On Tue, May 13, 2008 at 2:52 PM, Clinton Begin >> > >> > > > wrote: >> > > > > > Josh, >> > > > > > >> > > > > > Some people do care enough about this to do something about it. >> > And >> > > > > > yes, Hibernate is able to support it easily, because it has >> dirty >> > > > > > checking, object identity and generates the SQL for the update. >> > > > > > >> > > > > > iBATIS is a SQL based framework. It does not generate the SQL >> for >> > > > > > you, nor does it track dirty state or object identity etc. >> It's >> > > > > > pretty safe to say that iBATIS will never support this in any >> way, >> > > > > > even if we do add SQL generation for convenience, the lack of >> dirty >> > > > > > checking etc. will keep this from ever being a practical >> > possibility. >> > > > > > >> > > > > > I recommend looking into your particular situation. I'd bet >> that >> > it >> > > > > > doesn't matter as much as you think it does, or if it does >> matter >> > in >> > > > > > one or two cases -- handle those cases as a performance tweak. >> > > > > > >> > > > > > To answer your question about best practices, I'm not sure >> anyone >> > has >> > > > > > ever told me that this was a fully agreed upon best practice, >> but I >> > do >> > > > > > know a lot of people that think that premature performance >> > > > > > optimization is a practice to avoid... >> > > > > > >> > > > > > Cheers, >> > > > > > Clinton >> > > > > > >> > > > > > >> > > > > > >> > > > > > On Tue, May 13, 2008 at 2:37 PM, Josh Joy > > >> > wrote: >> > > > > > > >> > > > > > > >> > > > > > > Hi, >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > If I have an sql like the following... >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > Is there a way to instruct Ibatis to ignore nulls without >> having >> > to >> > > > actually >> > > > > > > use a dynamic tag? I would just like to set my bean entity >> with >> > the >> > > > > > > properties that I want updated, and leave null the ones I >> want to >> > > > ignore... >> > > > > > > >> > > > > > > I know in Hibernate there is a way to do this, is there an >> > equivalent >> > > > in >> > > > > > > Ibatis? It seems like a lot of xml code to write for all my >> > > > updates... >> > > > > > > >> > > > > > > Is this not a best practice not to have dynamic updates, >> because >> > I'm >> > > > unsure >> > > > > > > why I would have to explicitly set this in the XML? As far as >> I >> > know, >> > > > SQL >> > > > > > > updates (unless using a specific database vendor call) are on >> a >> > per >> > > > table >> > > > > > > basis. Is it not recommended to have an entity and not always >> > have to >> > > > update >> > > > > > > all the fields? If I wanted to modify the Ibatis API for my >> own >> > needs >> > > > for >> > > > > > > the updates, where would someone recommend I start? >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > > > Thanks, >> > > > > > > >> > > > > > > Josh >> > > > > > > >> > > > > > >> > > > > >> > > > >> > > > >> > > >> > >> > >> > > ------=_Part_13650_8674818.1211164451820 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline Josh,

One little point...  With your approach using dynamic tags you would never be able to set a column to null, which is a very real business case.

Nathan

On Tue, May 13, 2008 at 4:11 PM, Josh Joy <joshjdevl@gmail.com> wrote:
I guess I'll just look into this further then...I think I have a decent enough understanding of concurrency...I'm just of the mood to let the database handle the concurrency issues for me as much as possible rather bringing it to the java object side...

Going back to the original question...it seems that the answer is no...there is no other way to dynamically generate sql for updates for ibatis other than specifying the <dynamic> tag in sqll

(also it's not a business exception if the business allows different people to update only certain fields....)

Thanks for info,
Josh


On Tue, May 13, 2008 at 4:55 PM, Clinton Begin <clinton.begin@gmail.com> wrote:
Josh...

I think you really need to look into this further, as you have a
fundamental misunderstanding of concurrency issues and databases.

* Separating the updates at the column level will NOT solve any
concurrency problem
* Concurrency issues are solved using either an optimistic or
pessimistic locking model at the row level

I recommend optimistic for most systems.

Table Josh
 id
 name
 weburl
 timestamp

update josh set ..., timestamp = now() where id = ? and timestamp = ?

If the timestamps don't match, it's not simply a technical problem of
reloading the object. You have to tell the user what happened... it's
a business exception. What if the user would have changed the name
differently if the URL was different or vice versa?

Pessimistic locking would lock the record so that it could not be
updated (and in some cases not even read) until it's unlocked.  It's
rare to need this type of locking in most business applications.

This is a pretty core concept in database programming that you should
understand before using iBATIS, Hibernate or even just JDBC.  One book
I can recommend is Java Transaction Processing (Mark Little), page 11
- 12.

Any other book recommendations from anyone else?

Cheers,
Clinton

On Tue, May 13, 2008 at 3:36 PM, Josh Joy <joshjdevl@gmail.com> wrote:
>
> Table Josh
>   id
>   name
>   weburl
>
> If one user wants to update the name, and another user wants to update the
> weburl...how to avoid concurrency issues if I have to do a reload of the
> entire object?
> Please let me know how to configure Ibatis to handle state concurrency
> issues if I have to fetch the entire object...
>
>
> Thanks,
> Josh
>
>
>
>
> On Tue, May 13, 2008 at 4:25 PM, Clinton Begin <clinton.begin@gmail.com>
> wrote:
> > So is it completely out of the question to just load up the whole
> > object and save the whole object?  Why do you ever need any
> > conditionals or partial updates at all?  The only reason is
> > performance (and even that really depends on the details).
> >
> > I don't see the problem here... :-/
> >
> > Clinton
> >
> >
> >
> >
> > On Tue, May 13, 2008 at 3:11 PM, Josh Joy <joshjdevl@gmail.com> wrote:
> > > Thanks Clinton for your reply.
> > >
> > > Just to clarify...I'm not looking for any performance
> optimizations...when I
> > > say best practices I'm referring to dynamically choosing which fields to
> > > update...
> > >
> > > it comes down strictly to simplicity and readability...I don't see a
> reason
> > > to fetch the latest entries for a row just so I can do an update (and
> how
> > > can I possibly guarantee it's the latest entry) nor do I see a reason to
> > > write multiple update statements or an if statement laden sql for all
> the
> > > possible update situations that can occur...
> > >
> > > I'll start poking around the api to see if I can wrap something up for
> my
> > > needs for now I guess... (unless anyone has any other suggestions, code
> > > snippets, or patches to share...)
> > >
> > > Thanks,
> > > Josh
> > >
> > >
> > >
> > >  On Tue, May 13, 2008 at 3:53 PM, Clinton Begin
> <clinton.begin@gmail.com>
> > > wrote:
> > > > Wow, I managed to lay down 3 or 4 run-on sentences in a row there...
> > > > Sorry Mr. McMillan...
> > > >
> > > >
> > > >
> > > >
> > > > On Tue, May 13, 2008 at 2:52 PM, Clinton Begin
> <clinton.begin@gmail.com>
> > > wrote:
> > > > > Josh,
> > > > >
> > > > >  Some people do care enough about this to do something about it.
> And
> > > > >  yes, Hibernate is able to support it easily, because it has dirty
> > > > >  checking, object identity and generates the SQL for the update.
> > > > >
> > > > >  iBATIS is a SQL based framework.  It does not generate the SQL for
> > > > >  you, nor does it track dirty state or object identity etc.  It's
> > > > >  pretty safe to say that iBATIS will never support this in any way,
> > > > >  even if we do add SQL generation for convenience, the lack of dirty
> > > > >  checking etc. will keep this from ever being a practical
> possibility.
> > > > >
> > > > >  I recommend looking into your particular situation.  I'd bet that
> it
> > > > >  doesn't matter as much as you think it does, or if it does matter
> in
> > > > >  one or two cases -- handle those cases as a performance tweak.
> > > > >
> > > > >  To answer your question about best practices, I'm not sure anyone
> has
> > > > >  ever told me that this was a fully agreed upon best practice, but I
> do
> > > > >  know a lot of people that think that premature performance
> > > > >  optimization is a practice to avoid...
> > > > >
> > > > >  Cheers,
> > > > >  Clinton
> > > > >
> > > > >
> > > > >
> > > > >  On Tue, May 13, 2008 at 2:37 PM, Josh Joy <joshjdevl@gmail.com>
> wrote:
> > > > >  >
> > > > >  >
> > > > >  > Hi,
> > > > >  >
> > > > >  >
> > > > >  >
> > > > >  >
> > > > >  > If I have an sql like the following...
> > > > >  >
> > > > >  >
> > > > >  >
> > > > >  >
> > > > >  > <select id="updateEmployees" >
> > > > >  >
> > > > >  >      Update  emp
> > > > >  >
> > > > >  >       <dynamic prepend="WHERE">
> > > > >  >
> > > > >  >               set
> > > > >  >
> > > > >  >
> > > > >  >             <isNotEmpty prepend="AND" property="id">
> > > > >  >
> > > > >  >                   empno=#id#
> > > > >  >
> > > > >  >             </isNotEmpty>
> > > > >  >
> > > > >  >             <isNotEmpty prepend="OR" property="name">
> > > > >  >
> > > > >  >                   ename=#name#
> > > > >  >
> > > > >  >             </isNotEmpty>
> > > > >  >
> > > > >  >       </dynamic>
> > > > >  >
> > > > >  > </select>
> > > > >  >
> > > > >  >
> > > > >  >
> > > > >  >
> > > > >  > Is there a way to instruct Ibatis to ignore nulls without having
> to
> > > actually
> > > > >  > use a dynamic tag? I would just like to set my bean entity with
> the
> > > > >  > properties that I want updated, and leave null the ones I want to
> > > ignore...
> > > > >  >
> > > > >  > I know in Hibernate there is a way to do this, is there an
> equivalent
> > > in
> > > > >  > Ibatis? It seems like a lot of xml code to write for all my
> > > updates...
> > > > >  >
> > > > >  > Is this not a best practice not to have dynamic updates, because
> I'm
> > > unsure
> > > > >  > why I would have to explicitly set this in the XML? As far as I
> know,
> > > SQL
> > > > >  > updates (unless using a specific database vendor call) are on a
> per
> > > table
> > > > >  > basis. Is it not recommended to have an entity and not always
> have to
> > > update
> > > > >  > all the fields? If I wanted to modify the Ibatis API for my own
> needs
> > > for
> > > > >  > the updates, where would someone recommend I start?
> > > > >  >
> > > > >  >
> > > > >  >
> > > > >  >
> > > > >  > Thanks,
> > > > >  >
> > > > >  > Josh
> > > > >  >
> > > > >
> > > >
> > >
> > >
> >
>
>


------=_Part_13650_8674818.1211164451820--