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 Josh Joy <jo...@gmail.com> on 2009/10/13 14:38:12 UTC

[ibatis 3] insert return generated id?

Hi,

I'm using MS Sql Server 2005, previously with iBatis v2.x, I was able
to get the generated id from an insert as the return value for a
method.

With iBatis v3, the return value is always "1", which I'm assuming
means 1 row was inserted.

How can I configure the api to return the generated id from an insert?
For the insert, I am using keyProperty="id" useGeneratedKeys="true",
and that seems to work... my object property id has the generated id.
Though I would like it as the return value for the insert method as
well...

Thanks,
Josh

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: [ibatis 3] insert return generated id?

Posted by Clinton Begin <cl...@gmail.com>.
This is the code for insert, update and delete (there's only one concept of
"update").

    PreparedStatement ps = (PreparedStatement) statement;
    ps.execute();
    int rows = ps.getUpdateCount();
    Object parameterObject = boundSql.getParameterObject();
    KeyGenerator keyGenerator = mappedStatement.getKeyGenerator();
    keyGenerator.processAfter(executor, mappedStatement, ps,
parameterObject);
    return rows;

Clinton


On Tue, Oct 13, 2009 at 10:30 AM, Josh Joy <jo...@gmail.com> wrote:

> If the feature has been removed, could you please clarify what is the
> expected behavior if the return value for insert is not void?
>
> On Tue, Oct 13, 2009 at 10:46 AM, Clinton Begin <cl...@gmail.com>
> wrote:
> > Yes, removed.  It was made clear long ago, that iBATIS 3 would be a
> > completely new implementation.  Some features are not carried forward,
> > others are changed and there's a lot of new ones.  iBATIS is 7 years old.
> >  It was time to make some changes.
> > Cheers,
> > Clinton
> >
> > On Tue, Oct 13, 2009 at 9:32 AM, Rick.Wellman <Ri...@kiewit.com>
> > wrote:
> >>
> >> I have not looked at the source you’re referring to but did you
> >> “deprecate” the behavior or “remove” the behavior.  I am not sure if you
> >> have a standing policy on things like this but here is my opinion:
> >>
> >> I understand the need to “clean things up” in a major release but I tend
> >> to favor “formal deprecation” where possible to give the user community
> a
> >> migration path.
> >>
> >>
> >>
> >> If this has all decided and taken care of already, then (as the church
> >> lady says)…. Nevermind.
> >>
> >>
> >>
> >> From: Clinton Begin [mailto:clinton.begin@gmail.com]
> >> Sent: Tuesday, October 13, 2009 10:24 AM
> >> To: user-java@ibatis.apache.org; joshjdevl@gmail.com
> >> Subject: Re: [ibatis 3] insert return generated id?
> >>
> >>
> >>
> >> I deprecated that behaviour, because the API was inconsistent.  And then
> >> the question would arise, how do I get the row count for the number of
> rows
> >> inserted? (it's possible).
> >>
> >>
> >>
> >> So now the only way is to set the id on the objects themselves.  If you
> >> have a weird case where the ID is not on the parameter object, just wrap
> it
> >> in a Map.
> >>
> >>
> >>
> >> Clinton
> >>
> >> On Tue, Oct 13, 2009 at 6:38 AM, Josh Joy <jo...@gmail.com> wrote:
> >>
> >> Hi,
> >>
> >> I'm using MS Sql Server 2005, previously with iBatis v2.x, I was able
> >> to get the generated id from an insert as the return value for a
> >> method.
> >>
> >> With iBatis v3, the return value is always "1", which I'm assuming
> >> means 1 row was inserted.
> >>
> >> How can I configure the api to return the generated id from an insert?
> >> For the insert, I am using keyProperty="id" useGeneratedKeys="true",
> >> and that seems to work... my object property id has the generated id.
> >> Though I would like it as the return value for the insert method as
> >> well...
> >>
> >> Thanks,
> >> Josh
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> >> For additional commands, e-mail: user-java-help@ibatis.apache.org
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>

Re: [ibatis 3] insert return generated id?

Posted by Josh Joy <jo...@gmail.com>.
If the feature has been removed, could you please clarify what is the
expected behavior if the return value for insert is not void?

On Tue, Oct 13, 2009 at 10:46 AM, Clinton Begin <cl...@gmail.com> wrote:
> Yes, removed.  It was made clear long ago, that iBATIS 3 would be a
> completely new implementation.  Some features are not carried forward,
> others are changed and there's a lot of new ones.  iBATIS is 7 years old.
>  It was time to make some changes.
> Cheers,
> Clinton
>
> On Tue, Oct 13, 2009 at 9:32 AM, Rick.Wellman <Ri...@kiewit.com>
> wrote:
>>
>> I have not looked at the source you’re referring to but did you
>> “deprecate” the behavior or “remove” the behavior.  I am not sure if you
>> have a standing policy on things like this but here is my opinion:
>>
>> I understand the need to “clean things up” in a major release but I tend
>> to favor “formal deprecation” where possible to give the user community a
>> migration path.
>>
>>
>>
>> If this has all decided and taken care of already, then (as the church
>> lady says)…. Nevermind.
>>
>>
>>
>> From: Clinton Begin [mailto:clinton.begin@gmail.com]
>> Sent: Tuesday, October 13, 2009 10:24 AM
>> To: user-java@ibatis.apache.org; joshjdevl@gmail.com
>> Subject: Re: [ibatis 3] insert return generated id?
>>
>>
>>
>> I deprecated that behaviour, because the API was inconsistent.  And then
>> the question would arise, how do I get the row count for the number of rows
>> inserted? (it's possible).
>>
>>
>>
>> So now the only way is to set the id on the objects themselves.  If you
>> have a weird case where the ID is not on the parameter object, just wrap it
>> in a Map.
>>
>>
>>
>> Clinton
>>
>> On Tue, Oct 13, 2009 at 6:38 AM, Josh Joy <jo...@gmail.com> wrote:
>>
>> Hi,
>>
>> I'm using MS Sql Server 2005, previously with iBatis v2.x, I was able
>> to get the generated id from an insert as the return value for a
>> method.
>>
>> With iBatis v3, the return value is always "1", which I'm assuming
>> means 1 row was inserted.
>>
>> How can I configure the api to return the generated id from an insert?
>> For the insert, I am using keyProperty="id" useGeneratedKeys="true",
>> and that seems to work... my object property id has the generated id.
>> Though I would like it as the return value for the insert method as
>> well...
>>
>> Thanks,
>> Josh
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
>> For additional commands, e-mail: user-java-help@ibatis.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: [ibatis 3] insert return generated id?

Posted by Clinton Begin <cl...@gmail.com>.
Yes, removed.  It was made clear long ago, that iBATIS 3 would be a
completely new implementation.  Some features are not carried forward,
others are changed and there's a lot of new ones.  iBATIS is 7 years old.
 It was time to make some changes.
Cheers,
Clinton

On Tue, Oct 13, 2009 at 9:32 AM, Rick.Wellman <Ri...@kiewit.com>wrote:

>  I have not looked at the source you’re referring to but did you
> “deprecate” the behavior or “remove” the behavior.  I am not sure if you
> have a standing policy on things like this but here is my opinion:
>
> I understand the need to “clean things up” in a major release but I tend to
> favor “formal deprecation” where possible to give the user community a
> migration path.
>
>
>
> If this has all decided and taken care of already, then (as the church lady
> says)…. Nevermind.
>
>
>
> *From:* Clinton Begin [mailto:clinton.begin@gmail.com]
> *Sent:* Tuesday, October 13, 2009 10:24 AM
> *To:* user-java@ibatis.apache.org; joshjdevl@gmail.com
> *Subject:* Re: [ibatis 3] insert return generated id?
>
>
>
> I deprecated that behaviour, because the API was inconsistent.  And then
> the question would arise, how do I get the row count for the number of rows
> inserted? (it's possible).
>
>
>
> So now the only way is to set the id on the objects themselves.  If you
> have a weird case where the ID is not on the parameter object, just wrap it
> in a Map.
>
>
>
> Clinton
>
> On Tue, Oct 13, 2009 at 6:38 AM, Josh Joy <jo...@gmail.com> wrote:
>
> Hi,
>
> I'm using MS Sql Server 2005, previously with iBatis v2.x, I was able
> to get the generated id from an insert as the return value for a
> method.
>
> With iBatis v3, the return value is always "1", which I'm assuming
> means 1 row was inserted.
>
> How can I configure the api to return the generated id from an insert?
> For the insert, I am using keyProperty="id" useGeneratedKeys="true",
> and that seems to work... my object property id has the generated id.
> Though I would like it as the return value for the insert method as
> well...
>
> Thanks,
> Josh
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>
>

RE: [ibatis 3] insert return generated id?

Posted by "Rick.Wellman" <Ri...@kiewit.com>.
I have not looked at the source you're referring to but did you
"deprecate" the behavior or "remove" the behavior.  I am not sure if you
have a standing policy on things like this but here is my opinion:

I understand the need to "clean things up" in a major release but I tend
to favor "formal deprecation" where possible to give the user community
a migration path.

 

If this has all decided and taken care of already, then (as the church
lady says).... Nevermind.

 

From: Clinton Begin [mailto:clinton.begin@gmail.com] 
Sent: Tuesday, October 13, 2009 10:24 AM
To: user-java@ibatis.apache.org; joshjdevl@gmail.com
Subject: Re: [ibatis 3] insert return generated id?

 

I deprecated that behaviour, because the API was inconsistent.  And then
the question would arise, how do I get the row count for the number of
rows inserted? (it's possible).

 

So now the only way is to set the id on the objects themselves.  If you
have a weird case where the ID is not on the parameter object, just wrap
it in a Map.

 

Clinton

On Tue, Oct 13, 2009 at 6:38 AM, Josh Joy <jo...@gmail.com> wrote:

Hi,

I'm using MS Sql Server 2005, previously with iBatis v2.x, I was able
to get the generated id from an insert as the return value for a
method.

With iBatis v3, the return value is always "1", which I'm assuming
means 1 row was inserted.

How can I configure the api to return the generated id from an insert?
For the insert, I am using keyProperty="id" useGeneratedKeys="true",
and that seems to work... my object property id has the generated id.
Though I would like it as the return value for the insert method as
well...

Thanks,
Josh

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org

 


Re: [ibatis 3] insert return generated id?

Posted by Clinton Begin <cl...@gmail.com>.
I deprecated that behaviour, because the API was inconsistent.  And then the
question would arise, how do I get the row count for the number of rows
inserted? (it's possible).
So now the only way is to set the id on the objects themselves.  If you have
a weird case where the ID is not on the parameter object, just wrap it in a
Map.

Clinton

On Tue, Oct 13, 2009 at 6:38 AM, Josh Joy <jo...@gmail.com> wrote:

> Hi,
>
> I'm using MS Sql Server 2005, previously with iBatis v2.x, I was able
> to get the generated id from an insert as the return value for a
> method.
>
> With iBatis v3, the return value is always "1", which I'm assuming
> means 1 row was inserted.
>
> How can I configure the api to return the generated id from an insert?
> For the insert, I am using keyProperty="id" useGeneratedKeys="true",
> and that seems to work... my object property id has the generated id.
> Though I would like it as the return value for the insert method as
> well...
>
> Thanks,
> Josh
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>