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 Shardayyy <sh...@gmail.com> on 2006/03/19 05:24:06 UTC

Oracle insert - selectKey problem

Hey folks, 

 

 

I am having a problem getting this to work. Any help would be appreciated.
What am trying to do is insert a person and return the Id that was used in
inserting the person.

 

Target Database is Oracle 9.2

iBatis Version 2.1.7 - Jan 21, 2006

 

 

 

    <insert id="savePerson"  parameterClass="PersonObject"
resultClass="int">
            <selectKey  property="personId" type="pre"  resultClass="int">

                   select SEQ_PERSON.nextval as seqId from dual

          </selectKey>

        INSERT INTO PERSON_TBL ( personId, name, age,gender) VALUES
(#seqId#, #name#, #age#, #gender#)

    </insert>  

 

Error message is:

 

 

 


Re: Oracle insert - selectKey problem

Posted by Larry Meadors <lm...@apache.org>.
Why not this:

<select id="getNextVal" resultClass="java.lang.Integer">
  select $seq_name$.nextval from dual
</select>

Larry


On 3/20/06, Marco Berri <ma...@bluestudio.it> wrote:
> I'M Using this:
>
> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
> "$iBatisStoragePath$/sql-map-2.dtd">
> <sqlMap namespace="sequence">
>
>         <select id="getNextVal" resultClass="java.lang.Integer">
>                 select $seq_name$.nextval from tnes2.tnode where rownum=1
>         </select>
>
> </sqlMap>
>
> where tnes2.tnode is a table on my db.
>
>
>
>
> Larry Meadors wrote:
> > Also..make sure you are inserting with insert(), not update().
> >
> > Larry
> >
> >
> > On 3/18/06, Eric T. Blue <er...@gmail.com> wrote:
> >
> >>Hi,
> >>
> >> I believe your selectkey property name must match the #property# you are
> >>using for the insert statement.  So, you can either replace #seqId# with
> >>#personId#, or rename the selectKey property to seqId.  Also, I'm not
> >>certain if this has changed, but in the past when I've used selectKey the
> >>attribute for naming the key is keyProperty not property.
> >>
> >>
> >>On 3/18/06, Shardayyy <sh...@gmail.com> wrote:
> >>
> >>>
> >>>
> >>>
> >>>Hey folks,
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>I am having a problem getting this to work. Any help would be appreciated.
> >>
> >>What am trying to do is insert a person and return the Id that was used in
> >>inserting the person.
> >>
> >>>
> >>>
> >>>Target Database is Oracle 9.2
> >>>
> >>>iBatis Version 2.1.7 - Jan 21, 2006
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>      <insert id="savePerson"  parameterClass="PersonObject"
> >>
> >>resultClass="int"
> >>
> >>>            <selectKey  property="personId" type="pre"  resultClass=
> >>>"int">
> >>>
> >>>
> >>>                   select SEQ_PERSON.nextval as seqId from dual
> >>>
> >>>          </selectKey>
> >>>
> >>>        INSERT INTO PERSON_TBL ( personId, name, age,gender) VALUES
> >>
> >>(#seqId#, #name#, #age#, #gender#)
> >>
> >>>    </insert>
> >>>
> >>>
> >>>
> >>>Error message is:
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>
> >>
> >
> >
>

Re: Oracle insert - selectKey problem

Posted by Marco Berri <ma...@bluestudio.it>.
I'M Using this:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" 
"$iBatisStoragePath$/sql-map-2.dtd">
<sqlMap namespace="sequence">

	<select id="getNextVal" resultClass="java.lang.Integer">
		select $seq_name$.nextval from tnes2.tnode where rownum=1
	</select>
	
</sqlMap>

where tnes2.tnode is a table on my db.




Larry Meadors wrote:
> Also..make sure you are inserting with insert(), not update().
> 
> Larry
> 
> 
> On 3/18/06, Eric T. Blue <er...@gmail.com> wrote:
> 
>>Hi,
>>
>> I believe your selectkey property name must match the #property# you are
>>using for the insert statement.  So, you can either replace #seqId# with
>>#personId#, or rename the selectKey property to seqId.  Also, I'm not
>>certain if this has changed, but in the past when I've used selectKey the
>>attribute for naming the key is keyProperty not property.
>>
>>
>>On 3/18/06, Shardayyy <sh...@gmail.com> wrote:
>>
>>>
>>>
>>>
>>>Hey folks,
>>>
>>>
>>>
>>>
>>>
>>>I am having a problem getting this to work. Any help would be appreciated.
>>
>>What am trying to do is insert a person and return the Id that was used in
>>inserting the person.
>>
>>>
>>>
>>>Target Database is Oracle 9.2
>>>
>>>iBatis Version 2.1.7 - Jan 21, 2006
>>>
>>>
>>>
>>>
>>>
>>>      <insert id="savePerson"  parameterClass="PersonObject"
>>
>>resultClass="int"
>>
>>>            <selectKey  property="personId" type="pre"  resultClass=
>>>"int">
>>>
>>>
>>>                   select SEQ_PERSON.nextval as seqId from dual
>>>
>>>          </selectKey>
>>>
>>>        INSERT INTO PERSON_TBL ( personId, name, age,gender) VALUES
>>
>>(#seqId#, #name#, #age#, #gender#)
>>
>>>    </insert>
>>>
>>>
>>>
>>>Error message is:
>>>
>>>
>>>
>>>
>>>
>>>
>>
>>
> 
> 

Re: Oracle insert - selectKey problem

Posted by Larry Meadors <lm...@apache.org>.
Also..make sure you are inserting with insert(), not update().

Larry


On 3/18/06, Eric T. Blue <er...@gmail.com> wrote:
> Hi,
>
>  I believe your selectkey property name must match the #property# you are
> using for the insert statement.  So, you can either replace #seqId# with
> #personId#, or rename the selectKey property to seqId.  Also, I'm not
> certain if this has changed, but in the past when I've used selectKey the
> attribute for naming the key is keyProperty not property.
>
>
> On 3/18/06, Shardayyy <sh...@gmail.com> wrote:
> >
> >
> >
> >
> > Hey folks,
> >
> >
> >
> >
> >
> > I am having a problem getting this to work. Any help would be appreciated.
> What am trying to do is insert a person and return the Id that was used in
> inserting the person.
> >
> >
> >
> > Target Database is Oracle 9.2
> >
> > iBatis Version 2.1.7 - Jan 21, 2006
> >
> >
> >
> >
> >
> >       <insert id="savePerson"  parameterClass="PersonObject"
> resultClass="int"
> > >
> >             <selectKey  property="personId" type="pre"  resultClass=
> > "int">
> >
> >
> >                    select SEQ_PERSON.nextval as seqId from dual
> >
> >           </selectKey>
> >
> >         INSERT INTO PERSON_TBL ( personId, name, age,gender) VALUES
> (#seqId#, #name#, #age#, #gender#)
> >
> >     </insert>
> >
> >
> >
> > Error message is:
> >
> >
> >
> >
> >
> >
>
>

Re: Oracle insert - selectKey problem

Posted by "Eric T. Blue" <er...@gmail.com>.
Hi,

I believe your selectkey property name must match the #property# you are
using for the insert statement.  So, you can either replace #seqId# with
#personId#, or rename the selectKey property to seqId.  Also, I'm not
certain if this has changed, but in the past when I've used selectKey the
attribute for naming the key is keyProperty not property.

On 3/18/06, Shardayyy <sh...@gmail.com> wrote:
>
>  Hey folks,
>
>
>
>
>
> I am having a problem getting this to work. Any help would be appreciated.
> What am trying to do is insert a person and return the Id that was used in
> inserting the person.
>
>
>
> Target Database is Oracle 9.2
>
> iBatis Version 2.1.7 - Jan 21, 2006
>
>
>
>
>
>
>
>     <insert id="savePerson"  parameterClass="PersonObject" resultClass="int">
>
>             <selectKey  property="personId" type="pre"  resultClass="int">
>
>                    select SEQ_PERSON.nextval as seqId from dual
>
>           </selectKey>
>
>         INSERT INTO PERSON_TBL ( personId, name, age,gender) VALUES
> (#seqId#, #name#, #age#, #gender#)
>
>     </insert>
>
>
>
> Error message is:
>
>
>
>
>
>
>