ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Butler <jeffgbut...@gmail.com>
Subject Re: KeyProperty attribute in Selectkey Tag
Date Thu, 12 Feb 2009 18:13:15 GMT
Dude...seriously...*try it*.

The insert statement always returns the value of the select key, or
null if there is no select key.  In the example above, the return
value is Integer.  The keyProperty attribute is there for just this
instance - where you get the new key from a sequence before inserting.

Jeff Butler


On Thu, Feb 12, 2009 at 11:56 AM, Rahul Saluja <rahul.saluja@vnl.in> wrote:
> 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 Postgres).
>
>
>
> <insert id="MSCPerfCntrTrunkTblImpl"
>
> parameterClass="com.hns.hss.nmf.server.log.manager.gensrc.MSCPerformance.impl.MSCPerfCntrTrunkTblImpl">
>
>
>
>       <selectKey keyProperty="generatedSequenceId_0" resultClass="int">
>
>       SELECT nextval('MSCPerfCntrTrunk_seq')
>
>     </selectKey>
>
>       insert into MSCPerfCntrTrunkTbl(
>
>
>
> seq_no,
>
>       neinfo_id,
>
>       rectimeStamp,
>
>       transactionId,
>
>       destNum_2,
>
>
>
>       )
>
> values
>
>       (
>
>       #generatedSequenceId_0#,
>
>       #neInfoId_0#,
>
>       #timeStamp_0#,
>
>       #transactionId_1.value#,
>
>       #count_2.value#,
>
>
>
>       )
>
>
>
>
>
> And in my  java code  if I am writing following statements
>
>
>
>
> SqlMapClient.insert("MSCPerfCntrTrunkTblImpl",ObjectpointingtoMSCPerfCntrTrunkTblImpl)
>
>
>
> Above statement will return an Object but an object of what type??.
>
>
>
> Looking forward to your response.
>
>
>
> Regards
>
> 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
>
>
>
> Rahul,
>
>
>
> 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.
>
>
>
> Ex:
>
>   <selectKey resultClass="int" keyProperty="id">
>     SELECT max( pkey_column)+ 1 AS id from <table>
>
>   </selectKey>
>
>   INSERT INTO <table>
>
>   ( pkey_column,
>
>    <other column>,
>
>    <other column>,
>
>      ... )
>
>   VALUES
>
>    ( #id:INTEGER#,
>
>     value,
>
>     value,
>
> ...)
>
>
>
>
>
> 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.
>
>
>
> -Kevin
>
>
>
>
>
> -----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.
>
>
>
>
>
> Please.
>
> ________________________________
>
> 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.
>

Mime
View raw message