ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Karl Schwaerzler <Thomas.Schwaerz...@student.uibk.ac.at>
Subject RE: insert with id as return value (fwd)
Date Wed, 05 Jul 2006 17:32:36 GMT

you're right. that was the problem.

if i specify identity="false" everything works as expected as i ve been 
told by jeff butler already.

thanks for your help.

On Wed, 5 Jul 2006, Niels Beekman wrote:

> Hi,
>
> I don't have any experience with Abator but it seems logical to me that
> when you specify identity="true" Abator will generate the id
> select-query after insertion because identity means the database
> auto-generates it for you. What results do you get when you specify
> identity="false"?
>
> Niels
>
> -----Original Message-----
> From: Thomas Karl Schwaerzler
> [mailto:Thomas.Schwaerzler@student.uibk.ac.at]
> Sent: woensdag 5 juli 2006 18:46
> To: user-java@ibatis.apache.org
> Subject: Re: insert with id as return value (fwd)
>
>
> hello again,
>
>
> i have tried this in different versions but cant get the expected
> result:
>
> here my table definition as sql:
>
>  ID                                        NOT NULL NUMBER
>  WORKFLOW_ID                               NOT NULL NUMBER
>  ACTION_ID                                 NOT NULL NUMBER
>  URL                                       NOT NULL VARCHAR2(255)
>  NAME                                      NOT NULL VARCHAR2(255)
>  TARGET                                             VARCHAR2(255)
>
>
>
> here my table definition in abatorConfig.xml:
>
>   <table schema="c108272dev" tableName="ODM_LINK">
>    		<generatedKey identity="true" column="id"
> sqlStatement="SELECT
> c108272dev.ODM_LINK_COUNTER.nextval AS id FROM dual" />
>     </table>
>
>
>
> the sqlmap i get looks like this:
>
>  <insert id="abatorgenerated_insert"
> parameterClass="org.dea.odm.model.abator.model.OdmLink">
>     <!--
>       WARNING - This element is automatically generated by Abator for
> iBATIS,
> do not modify.
>       This element was generated on Wed Jul 05 18:19:23 CEST 2006.
>     -->
>     insert into c108272dev.ODM_LINK (WORKFLOW_ID, ACTION_ID, URL, NAME,
> TARGET)
>     values (#workflowId:DECIMAL#, #actionId:DECIMAL#, #url:VARCHAR#,
>       #name:VARCHAR#, #target:VARCHAR#)
>
>     <selectKey keyProperty="id" resultClass="java.lang.Long">
>       SELECT c108272dev.ODM_LINK_COUNTER.nextval AS id FROM dual
>     </selectKey>
>   </insert>
>
>
>
> .. and i'm missing the ID to be inserted and taken from the query below.
>
>
> the desired result would be something like this:
>
>
> 	<insert id="insertLink"
> parameterClass="org.dea.odm.model.dao.beans.LinkDaoBean">
> 		<selectKey resultClass="long" keyProperty="id">
>     		select ODM_LINK_COUNTER.NEXTVAL as "id" from dual
>   		</selectKey>
> 		INSERT INTO ODM_LINK
> 		(ID, WORKFLOW_ID, ACTION_ID, URL, NAME, TARGET)
> 		VALUES (#id#, #workflowId#, #actionId#, #url#, #name#,
> #target#)
> 	</insert>
>
>
>
>
> .. i cant find out why ibatis does not insert the primary key 'id' ...
>
>
> thanks for advices
> tom.
>
>
> On Tue, 4 Jul 2006, Jeff Butler wrote:
>
>> The iBATIS function you are looking for is <selectKey> - this is
>> specifically designed for this situation.
>>
>> Abator will generate <selectKey> statements for you if you use the
>> <generatedKey> Abator configuration element.
>>
>> Jeff Butler
>>
>>
>>
>>
>> On 7/4/06, Thomas Karl Schwaerzler
> <Thomas.Schwaerzler@student.uibk.ac.at>
>> wrote:
>>>
>>>
>>> hi,
>>>
>>> doesn't really look like:
>>>
>>> OdmLinkDAOImpl.java:
>>>
>>> <snip>
>>>
>>>    /**
>>>      * This method was generated by Abator for iBATIS.
>>>      * This method corresponds to the database table
> c108272dev.ODM_LINK
>>>      *
>>>      * @abatorgenerated Tue Jul 04 18:48:58 CEST 2006
>>>      */
>>>     public void insert(OdmLink record) {
>>>         insert("c108272dev_ODM_LINK.abatorgenerated_insert", record);
>>>     }
>>>
>>>
>>> </snip>
>>>
>>> greets
>>> tom.
>>>
>>> On Tue, 4 Jul 2006, Graeme J Sweeney wrote:
>>>
>>>> On Tue, 4 Jul 2006, Thomas Karl Schwaerzler wrote:
>>>>
>>>> You don't have to do this
>>>>
>>>>>              link.setId(id);
>>>>
>>>> as this call
>>>>
>>>>>              linkDao.insert(link);
>>>>
>>>> will return you the id. Check the javadoc of your DAO (or
>>> LinkDAOImpl.java).
>>>>
>>>> --
>>>> Graeme -
>>>>
>>>
>>
>

Mime
View raw message