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 16:50:41 GMT
There is no way a framework would be able to accomplish that apart
from exactly what you stated. You should assure the verasity of the
object you want to insert before you attempt to insert it. That will
always happen against the databsae even if you created a memory
resident object identity layer. The other option would be to place
those checks a little closer to the database in the form of a stored
procedure.

Brandon


On Wed, 23 Feb 2005 16:06:22 +0000, Tim Christopher
<tim.christopher@gmail.com> wrote:
> 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