ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rahul Saluja <rahul.sal...@vnl.in>
Subject RE: KeyProperty attribute in Selectkey Tag
Date Thu, 12 Feb 2009 17:56:44 GMT
Hey Bruke,

Well I do have sequences defined for my each table which acts as a primary key for my table
now I want to use this generatedkey as a foreign key in another table so now if I use my class
attribute to have this sequence id , then how can I get that key in java code , I am assuming
I can do in following manner please tell me if I a, doing in a right way or not (my DB is

<insert id="MSCPerfCntrTrunkTblImpl"

      <selectKey keyProperty="generatedSequenceId_0" resultClass="int">
      SELECT nextval('MSCPerfCntrTrunk_seq')
      insert into MSCPerfCntrTrunkTbl(




And in my  java code  if I am writing following statements


Above statement will return an Object but an object of what type??.

Looking forward to your response.

Rahul Saluja
From: Burke.Kevin [mailto:Kevin.Burke@cic.gc.ca]
Sent: Thursday, February 12, 2009 11:17 PM
To: user-java@ibatis.apache.org
Subject: RE: KeyProperty attribute in Selectkey Tag


My experience with this tag is you use it to define a query to determine your primary key,
in the absence of, say an IDENTITY column.

You need to specify the keyProperty attribute if you want the following SQL to be able to
utilize the result of the query.  In the following example, I utilize an integer based primary
key column.  The following allows me to manage the primary keys myself, without an auto-incrementing
identity column.

  <selectKey resultClass="int" keyProperty="id">
    SELECT max( pkey_column)+ 1 AS id from <table>
  INSERT INTO <table>
  ( pkey_column,
   <other column>,
   <other column>,
     ... )
   ( #id:INTEGER#,

I guess there is a possibility that you could have concurrency issues, unless you synchronize
access on the DAO methods invoking this statement.  Otherwise, you could experience another
thread attemping an insert between the <selectKey> query to determine the next value,
and the actual insert in your statement.


-----Original Message-----
From: Rahul Saluja [mailto:rahul.saluja@vnl.in]
Sent: February 12, 2009 12:00 PM
To: user-java@ibatis.apache.org
Subject: RE: KeyProperty attribute in Selectkey Tag

Does anybody care to reply.

The information contained in this e-mail is private & confidential and may also be legally
privileged. If you are not the intended recipient, please notify us, preferably by e-mail,
and do not read, copy or disclose the contents of this message to anyone.

View raw message