Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 19797 invoked from network); 14 Oct 2005 03:40:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 14 Oct 2005 03:40:08 -0000 Received: (qmail 98620 invoked by uid 500); 14 Oct 2005 03:40:07 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 98234 invoked by uid 500); 14 Oct 2005 03:40:06 -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 Delivered-To: moderator for user-java@ibatis.apache.org Received: (qmail 70417 invoked by uid 99); 14 Oct 2005 02:52:37 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=HTML_MESSAGE X-Spam-Check-By: apache.org Received-SPF: neutral (asf.osuosl.org: local policy) Message-ID: <434F1D7C.2040308@flavor8.com> Date: Thu, 13 Oct 2005 19:52:44 -0700 From: reuben Reply-To: reubenf@sonic.net User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050912) X-Accept-Language: en-us, en MIME-Version: 1.0 To: user-java@ibatis.apache.org Subject: Re: multiple selectKeys in same transaction; wrong value coming out References: <21522.216.239.124.38.1129168583.squirrel@webmail.sonic.net> In-Reply-To: Content-Type: multipart/alternative; boundary="------------030102030909020400050200" X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N This is a multi-part message in MIME format. --------------030102030909020400050200 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Sybase, unfortunately, not MSSQL. I took out the batch from the transaction, and everything now works. I don't understand why it made a difference (the selectKeys were *not* in the same batch, just in the same transaction) but oh well. Larry Meadors wrote: >Can you try this using scope_identity() instead of @@identity? > >That *may* fix the problem. > >Larry > > >On 10/12/05, reubenf@sonic.net wrote: > > >>Hello, I am doing the following within one transaction: >> >>createJob(Job job); >> >>[somewhat heavy calculations that don't belong in the batch] >> >>begin batch: >> createDeployment(Deployment deployment); >> ... >>end batch; >> >>My problem is that after the batch is run, the deployment has the job's >>id. (The setters on the beans are respectively correct.) >> >>The xml invoked by createJob looks like this: >> >> >> INSERT INTO Job (userName) >> VALUES (#userName#) >> >> SELECT @@IDENTITY as value >> >> >> >>The xml invoked by createDeployment looks like this: >> >> >> INSERT INTO Deployment ( >> environmentId, deploymentTypeId, deploymentStatusId, >>deploymentTime, threadCountOverride >> ) VALUES ( >> #environmentId#, #deploymentTypeId#, #deploymentStatusId#, >>#deploymentTime#, #threadCountOverride# >> ) >> >> SELECT @@IDENTITY as value >> >> >> >>I am using Spring transactions and batches, but I have verified that the >>ibatis objects (& batch) are apparently being set up correctly. >> >> >> >> >> > > > > --------------030102030909020400050200 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sybase, unfortunately, not MSSQL.

I took out the batch from the transaction, and everything now works. I don't understand why it made a difference (the selectKeys were *not* in the same batch, just in the same transaction) but oh well.

Larry Meadors wrote:
Can you try this using scope_identity() instead of @@identity?

That *may* fix the problem.

Larry


On 10/12/05, reubenf@sonic.net <reubenf@sonic.net> wrote:
  
Hello, I am doing the following within one transaction:

createJob(Job job);

[somewhat heavy calculations that don't belong in the batch]

begin batch:
     createDeployment(Deployment deployment);
     ...
end batch;

My problem is that after the batch is run, the deployment has the job's
id. (The setters on the beans are respectively correct.)

The xml invoked by createJob looks like this:

    <insert id="createJob" parameterClass="job">
        INSERT INTO Job (userName)
        VALUES (#userName#)
        <selectKey resultClass="int" keyProperty="jobId">
            SELECT @@IDENTITY as value
        </selectKey>
    </insert>

The xml invoked by createDeployment looks like this:

    <insert id="createDeployment" parameterClass="deployment">
        INSERT INTO Deployment (
            environmentId, deploymentTypeId, deploymentStatusId,
deploymentTime, threadCountOverride
        ) VALUES (
            #environmentId#, #deploymentTypeId#, #deploymentStatusId#,
#deploymentTime#, #threadCountOverride#
        )
        <selectKey resultClass="int" keyProperty="deploymentId">
            SELECT @@IDENTITY as value
        </selectKey>
    </insert>

I am using Spring transactions and batches, but I have verified that the
ibatis objects (& batch) are apparently being set up correctly.



    


  

--------------030102030909020400050200--