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 Thomas Karl Schwaerzler <Th...@student.uibk.ac.at> on 2006/07/05 18:46:28 UTC
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 <Th...@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 -
>> >
>>
>