You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by re...@sonic.net on 2005/10/13 03:56:23 UTC
multiple selectKeys in same transaction; wrong value coming out
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.
Re: multiple selectKeys in same transaction; wrong value coming out
Posted by reuben <rf...@flavor8.com>.
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 <re...@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.
>>
>>
>>
>>
>>
>
>
>
>
Re: multiple selectKeys in same transaction; wrong value coming out
Posted by Larry Meadors <lm...@apache.org>.
Can you try this using scope_identity() instead of @@identity?
That *may* fix the problem.
Larry
On 10/12/05, reubenf@sonic.net <re...@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.
>
>
>