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 Larry Meadors <lm...@apache.org> on 2007/11/01 17:37:28 UTC

Re: Problem with insertKey

Try

SELECT obituary_seq.NEXTVAL AS id FROM dual

instead (id, not value).

Larry


On 11/1/07, Odelya Glick <od...@jpost.com> wrote:
> Well,
>
> I changed it, but it always puts value 0.
>
> The sequence is declared like this:
>
> CREATE SEQUENCE obituary_seq
>     INCREMENT BY 3
>     START WITH 100
>     NOMAXVALUE
>     MINVALUE 100
>     NOCYCLE
>     CACHE 20
>     NOORDER
>
> What could be the problem?
>
> Many thanks,
>
> Odelya
>
>
> -----Original Message-----
> From: Jean-Francois Poilpret [mailto:jfpoilpret@yahoo.fr]
> Sent: Thursday, November 01, 2007 4:40 PM
> To: user-java@ibatis.apache.org
> Subject: RE: Problem with insertKey
>
> An Oracle sequence cannot map to a String, so your condolence class should
> have the following properties:
> int id; (or long)
> String status;
>
> Cheers
>
> Jean-Francois
>
> -----Original Message-----
> From: Odelya Glick [mailto:odelya@jpost.com]
> Sent: Friday, November 02, 2007 9:21 AM
> To: user-java@ibatis.apache.org
> Subject: Problem with insertKey
>
>
> Hi,
>
> I am trying to receive primary key with:
> <insert id="insertCondolence" parameterClass="condolence">
>                 <selectKey keyProperty="id" resultClass="int">
>                         SELECT obituary_seq.NEXTVAL AS value FROM dual
>                 </selectKey>
>                 INSERT INTO CONDOLENCE(ID, STATUS)
>                 VALUES(#id#,#status#)
>         </insert>
>
> The condolence class has 2 properties:
> String id;
> String status;
>
> But it always inserts a record with the right status value, but id value is
> always null!!
>
> Why?
>
> Thanks
> Odelya
> web-programmer
> 050-2052075
>
>
>
>
>
>
>
>
> ****************************************************************************
> ********
> This footnote confirms that this email message has been scanned by
> PineApp Mail-SeCure for the presence of malicious code, vandals & computer
> viruses.
> ****************************************************************************
> ********
>
>
>
>
>

RE: Problem with insertKey

Posted by Jean-Francois Poilpret <jf...@yahoo.fr>.
Please check that your Java code calls sqlMapClient.insert(...) and not
sqlMapClient.update(...). the <selectKey> tag works only (AFAIR) with
insert().

Cheers

Jean-Francois

-----Original Message-----
From: Odelya Glick [mailto:odelya@jpost.com] 
Sent: Sunday, November 04, 2007 7:54 AM
To: user-java@ibatis.apache.org; lmeadors@apache.org
Subject: RE: Problem with insertKey

I tried it.

Now it looks like this:
<insert id="insertCondolence" parameterClass="condolence">
		<selectKey keyProperty="id" resultClass="int">
			SELECT obituary_seq.NEXTVAL AS ID FROM DUAL
		</selectKey>
		INSERT INTO JPCONDOLENCE(ID, STATUS, OBIT_ID, CREATED_DATE,
		AUTHOR_NAME, COUNTRY, AUTHOR_EMAIL, BODY, CITY)
	
VALUES(#id#,#status#,#obitId#,#createdDate#,#authorName#,#country#,#authorEm
ail#,#body#,#city#)
	</insert>

But still I get 0 as id.

Just to mention, when I run query:
<select id="getNextSequence" resultClass="string">
		SELECT obituary_seq.NEXTVAL AS ID FROM DUAL
	</select>
I do get the NextSequence from DB.

P.S. Is the above way to get the next sequence equals concerning database
performances? 

Thank you, 

-----Original Message-----
From: larry.meadors@gmail.com [mailto:larry.meadors@gmail.com] On Behalf Of
Larry Meadors
Sent: Thursday, November 01, 2007 6:37 PM
To: user-java@ibatis.apache.org
Subject: Re: Problem with insertKey

Try

SELECT obituary_seq.NEXTVAL AS id FROM dual

instead (id, not value).

Larry


On 11/1/07, Odelya Glick <od...@jpost.com> wrote:
> Well,
>
> I changed it, but it always puts value 0.
>
> The sequence is declared like this:
>
> CREATE SEQUENCE obituary_seq
>     INCREMENT BY 3
>     START WITH 100
>     NOMAXVALUE
>     MINVALUE 100
>     NOCYCLE
>     CACHE 20
>     NOORDER
>
> What could be the problem?
>
> Many thanks,
>
> Odelya
>
>
> -----Original Message-----
> From: Jean-Francois Poilpret [mailto:jfpoilpret@yahoo.fr]
> Sent: Thursday, November 01, 2007 4:40 PM
> To: user-java@ibatis.apache.org
> Subject: RE: Problem with insertKey
>
> An Oracle sequence cannot map to a String, so your condolence class should
> have the following properties:
> int id; (or long)
> String status;
>
> Cheers
>
> Jean-Francois
>
> -----Original Message-----
> From: Odelya Glick [mailto:odelya@jpost.com]
> Sent: Friday, November 02, 2007 9:21 AM
> To: user-java@ibatis.apache.org
> Subject: Problem with insertKey
>
>
> Hi,
>
> I am trying to receive primary key with:
> <insert id="insertCondolence" parameterClass="condolence">
>                 <selectKey keyProperty="id" resultClass="int">
>                         SELECT obituary_seq.NEXTVAL AS value FROM dual
>                 </selectKey>
>                 INSERT INTO CONDOLENCE(ID, STATUS)
>                 VALUES(#id#,#status#)
>         </insert>
>
> The condolence class has 2 properties:
> String id;
> String status;
>
> But it always inserts a record with the right status value, but id value
is
> always null!!
>
> Why?
>
> Thanks
> Odelya
> web-programmer
> 050-2052075
>
>
>
>
>
>
>
>
>
****************************************************************************
> ********
> This footnote confirms that this email message has been scanned by
> PineApp Mail-SeCure for the presence of malicious code, vandals & computer
> viruses.
>
****************************************************************************
> ********
>
>
>
>
>



 
 
****************************************************************************
********
This footnote confirms that this email message has been scanned by
PineApp Mail-SeCure for the presence of malicious code, vandals & computer
viruses.
****************************************************************************
********





Re: Problem with insertKey

Posted by Larry Meadors <lm...@apache.org>.
And you are sure you are using the insert() method of the SQL Map Client?

Larry


On 11/3/07, Odelya Glick <od...@jpost.com> wrote:
> I tried it.
>
> Now it looks like this:
> <insert id="insertCondolence" parameterClass="condolence">
>                 <selectKey keyProperty="id" resultClass="int">
>                         SELECT obituary_seq.NEXTVAL AS ID FROM DUAL
>                 </selectKey>
>                 INSERT INTO JPCONDOLENCE(ID, STATUS, OBIT_ID, CREATED_DATE,
>                 AUTHOR_NAME, COUNTRY, AUTHOR_EMAIL, BODY, CITY)
>
> VALUES(#id#,#status#,#obitId#,#createdDate#,#authorName#,#country#,#authorEm
> ail#,#body#,#city#)
>         </insert>
>
> But still I get 0 as id.
>
> Just to mention, when I run query:
> <select id="getNextSequence" resultClass="string">
>                 SELECT obituary_seq.NEXTVAL AS ID FROM DUAL
>         </select>
> I do get the NextSequence from DB.
>
> P.S. Is the above way to get the next sequence equals concerning database
> performances?
>
> Thank you,
>
> -----Original Message-----
> From: larry.meadors@gmail.com [mailto:larry.meadors@gmail.com] On Behalf Of
> Larry Meadors
> Sent: Thursday, November 01, 2007 6:37 PM
> To: user-java@ibatis.apache.org
> Subject: Re: Problem with insertKey
>
> Try
>
> SELECT obituary_seq.NEXTVAL AS id FROM dual
>
> instead (id, not value).
>
> Larry
>
>
> On 11/1/07, Odelya Glick <od...@jpost.com> wrote:
> > Well,
> >
> > I changed it, but it always puts value 0.
> >
> > The sequence is declared like this:
> >
> > CREATE SEQUENCE obituary_seq
> >     INCREMENT BY 3
> >     START WITH 100
> >     NOMAXVALUE
> >     MINVALUE 100
> >     NOCYCLE
> >     CACHE 20
> >     NOORDER
> >
> > What could be the problem?
> >
> > Many thanks,
> >
> > Odelya
> >
> >
> > -----Original Message-----
> > From: Jean-Francois Poilpret [mailto:jfpoilpret@yahoo.fr]
> > Sent: Thursday, November 01, 2007 4:40 PM
> > To: user-java@ibatis.apache.org
> > Subject: RE: Problem with insertKey
> >
> > An Oracle sequence cannot map to a String, so your condolence class should
> > have the following properties:
> > int id; (or long)
> > String status;
> >
> > Cheers
> >
> > Jean-Francois
> >
> > -----Original Message-----
> > From: Odelya Glick [mailto:odelya@jpost.com]
> > Sent: Friday, November 02, 2007 9:21 AM
> > To: user-java@ibatis.apache.org
> > Subject: Problem with insertKey
> >
> >
> > Hi,
> >
> > I am trying to receive primary key with:
> > <insert id="insertCondolence" parameterClass="condolence">
> >                 <selectKey keyProperty="id" resultClass="int">
> >                         SELECT obituary_seq.NEXTVAL AS value FROM dual
> >                 </selectKey>
> >                 INSERT INTO CONDOLENCE(ID, STATUS)
> >                 VALUES(#id#,#status#)
> >         </insert>
> >
> > The condolence class has 2 properties:
> > String id;
> > String status;
> >
> > But it always inserts a record with the right status value, but id value
> is
> > always null!!
> >
> > Why?
> >
> > Thanks
> > Odelya
> > web-programmer
> > 050-2052075
> >
> >
> >
> >
> >
> >
> >
> >
> >
> ****************************************************************************
> > ********
> > This footnote confirms that this email message has been scanned by
> > PineApp Mail-SeCure for the presence of malicious code, vandals & computer
> > viruses.
> >
> ****************************************************************************
> > ********
> >
> >
> >
> >
> >
>
>
>
>
>
> ****************************************************************************
> ********
> This footnote confirms that this email message has been scanned by
> PineApp Mail-SeCure for the presence of malicious code, vandals & computer
> viruses.
> ****************************************************************************
> ********
>
>
>
>
>

RE: Problem with insertKey

Posted by Odelya Glick <od...@jpost.com>.
I tried it.

Now it looks like this:
<insert id="insertCondolence" parameterClass="condolence">
		<selectKey keyProperty="id" resultClass="int">
			SELECT obituary_seq.NEXTVAL AS ID FROM DUAL
		</selectKey>
		INSERT INTO JPCONDOLENCE(ID, STATUS, OBIT_ID, CREATED_DATE,
		AUTHOR_NAME, COUNTRY, AUTHOR_EMAIL, BODY, CITY)
	
VALUES(#id#,#status#,#obitId#,#createdDate#,#authorName#,#country#,#authorEm
ail#,#body#,#city#)
	</insert>

But still I get 0 as id.

Just to mention, when I run query:
<select id="getNextSequence" resultClass="string">
		SELECT obituary_seq.NEXTVAL AS ID FROM DUAL
	</select>
I do get the NextSequence from DB.

P.S. Is the above way to get the next sequence equals concerning database
performances? 

Thank you, 

-----Original Message-----
From: larry.meadors@gmail.com [mailto:larry.meadors@gmail.com] On Behalf Of
Larry Meadors
Sent: Thursday, November 01, 2007 6:37 PM
To: user-java@ibatis.apache.org
Subject: Re: Problem with insertKey

Try

SELECT obituary_seq.NEXTVAL AS id FROM dual

instead (id, not value).

Larry


On 11/1/07, Odelya Glick <od...@jpost.com> wrote:
> Well,
>
> I changed it, but it always puts value 0.
>
> The sequence is declared like this:
>
> CREATE SEQUENCE obituary_seq
>     INCREMENT BY 3
>     START WITH 100
>     NOMAXVALUE
>     MINVALUE 100
>     NOCYCLE
>     CACHE 20
>     NOORDER
>
> What could be the problem?
>
> Many thanks,
>
> Odelya
>
>
> -----Original Message-----
> From: Jean-Francois Poilpret [mailto:jfpoilpret@yahoo.fr]
> Sent: Thursday, November 01, 2007 4:40 PM
> To: user-java@ibatis.apache.org
> Subject: RE: Problem with insertKey
>
> An Oracle sequence cannot map to a String, so your condolence class should
> have the following properties:
> int id; (or long)
> String status;
>
> Cheers
>
> Jean-Francois
>
> -----Original Message-----
> From: Odelya Glick [mailto:odelya@jpost.com]
> Sent: Friday, November 02, 2007 9:21 AM
> To: user-java@ibatis.apache.org
> Subject: Problem with insertKey
>
>
> Hi,
>
> I am trying to receive primary key with:
> <insert id="insertCondolence" parameterClass="condolence">
>                 <selectKey keyProperty="id" resultClass="int">
>                         SELECT obituary_seq.NEXTVAL AS value FROM dual
>                 </selectKey>
>                 INSERT INTO CONDOLENCE(ID, STATUS)
>                 VALUES(#id#,#status#)
>         </insert>
>
> The condolence class has 2 properties:
> String id;
> String status;
>
> But it always inserts a record with the right status value, but id value
is
> always null!!
>
> Why?
>
> Thanks
> Odelya
> web-programmer
> 050-2052075
>
>
>
>
>
>
>
>
>
****************************************************************************
> ********
> This footnote confirms that this email message has been scanned by
> PineApp Mail-SeCure for the presence of malicious code, vandals & computer
> viruses.
>
****************************************************************************
> ********
>
>
>
>
>



 
 
****************************************************************************
********
This footnote confirms that this email message has been scanned by
PineApp Mail-SeCure for the presence of malicious code, vandals & computer
viruses.
****************************************************************************
********