ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ron Chan <rc...@i-tao.com>
Subject Re: Obtain generated ID
Date Sat, 10 Jan 2009 13:11:00 GMT

you shouldn't need to run another select

you should find the id of the Dictionary class populated with the generated
key after running the insert

LiborP wrote:
> Hi all,
> I'm new in iBatis. I'm using Swing, Spring, iBatis and Apache Derby in my
> desktop project. I'm struggling with receive inserted ID. I'm not able to
> find out last inserted ID. To generate new ID I'm using Derby function
> IDENTITY_VAL_LOCAL(). This function works fine for generating ID. This is
> snipped of relevant code:
> <insert id="insertDictionary"  parameterClass="Dictionary" > 
>     insert into Dictionary (  id,  word,  value,  description, idLesson)
>     values ( DEFAULT,
>     #key#, #translation#, #description# ,#idLesson# ) 
>     <selectKey keyProperty="id" type="pre" resultClass="int">
>       values IDENTITY_VAL_LOCAL()
>       </selectKey>
> </insert>
> DAO snipped:
> return getSqlMapClientTemplate().insert("Dictionary.insertDictionary",
> dictionary);
> I tried to create another select to get last inserted ID like this:
> <select id="lastInsertedID" resultClass="Integer">
> </select>
> but it returns null as well. I tried to use "values IDENTITY_VAL_LOCAL()"
> in SQL client and it works fine.
> I'm not using transactions. iBatis version, Derby version
> Can anybody help please?

View this message in context: http://www.nabble.com/Obtain-generated-ID-tp21372327p21387974.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.

View raw message