ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brandon Goodin <brandon.goo...@gmail.com>
Subject Re: Duplicate Key in Db
Date Wed, 23 Feb 2005 17:07:13 GMT
eeek... recovery via exceptions is an anti-pattern. This is not an
exception issue. It is a validation issue.

Brandon


On Wed, 23 Feb 2005 11:54:59 -0500, Akins, Greg <gakins@amervideo.com> wrote:
> Can you perform the insert, and capture the error that comes back on the
> SQLException?
> 
> -----Original Message-----
> From: Tim Christopher [mailto:tim.christopher@gmail.com]
> Sent: Wednesday, February 23, 2005 11:06 AM
> To: ibatis-user-java@incubator.apache.org
> Subject: Re: Duplicate Key in Db
> 
> Sorry, I should have mentioned that I was talking about an insertion...
> Currently it is possible for a user to create a new Module by specifying
> a module code, name, etc..  The module code is a primary key and must be
> a unique value, though it must match with a value stored in another
> system so can not be an auto-increment value.
> 
> Is there any way to prevent a user from creating two modules with the
> same Id, other than doing a select statement first to see if it will
> break any database rules.  Doing it that way would mean any change to
> the database structure such as the removal of a primary keep will
> require an update to my Java classes.
> 
> I was hoping there is a way for iBATIS catch the error and return
> something to let the user know their attempted insertion was invalid and
> was not completed.
> 
> Tim Christopher
> 
> On Wed, 23 Feb 2005 08:38:38 -0700, Brandon Goodin
> <brandon.goodin@gmail.com> wrote:
> > you should not specify your primary key in the update values of your
> > update statement. It should be part of your where criteria.
> >
> > BAD:
> > UPDATE SOMETABLE
> > (somePrimaryKey,columnA,columnB,columnC)
> > VALUES(#somePrimaryKey#,#'valueA#,#valueB#,#valueC#)
> > WHERE somePrimaryKey = 1
> >
> > GOOD:
> > UPDATE SOMETABLE
> > (columnA,columnB,columnC)
> > VALUES(#valueA#,#valueB#,#valueC#)
> > WHERE somePrimaryKey =  #somePrimaryKey#
> >
> > Brandon
> >
> > On Wed, 23 Feb 2005 12:00:34 +0000, Tim Christopher
> > <tim.christopher@gmail.com> wrote:
> > > Hi,
> > >
> > > Apologies is this question is trivial for the group but I'm very new
> 
> > > to using iBATIS.
> > >
> > > I've managed to successfully integrate iBATIS into my Struts
> > > application, using a structure much like the sample JPetStore
> > > project
> > > - this acted as my tutorial.
> > >
> > > Can someone let me know if it is possible for iBATIS to deal with
> > > problems such as an update containing a primary key which is the
> > > same as on already in the table?
> > >
> > > I tested this out this morning on got a huge stack trace (summarised
> 
> > > below), so I'm guessing it isn't done by default.
> > >
> > > >>>>
> > > Cause: com.borland.datastore.driver.SqlState: Runtime Error: [line
> > > 1, col 6] Duplicate key value for $UNIQUE$1 sort order in "MODULE".
> > > <<<<
> > >
> > > Any advice or even just a link would be much appreciated.
> > >
> > > Regards,
> > >
> > > Tim Christopher
> > >
> >
>

Mime
View raw message