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 Koka <22...@gmail.com> on 2005/08/05 16:32:29 UTC

Trouble with oracle 10g selectKey

Wow, seems I'm dumb-minded today, can not make selectKey work....

Following the SQL-Maps-2.pdf I have:

<insert id='insertService' parameterClass='service'>
        <selectKey resultClass='int'>
            select services_seq.nextval as service_id from dual
        </selectKey>
	 insert into Services ( service_id,service_name) 
		 values ( #service_id#,#service_name#) 
</insert>

and dao (I'm using spring) looks like

public class ObjectDao extends SqlMapClientDaoSupport

public int insertObject(Object object) throws DataAccessException
    {
//        Service service = (Service) object;
//        if (service.getService_id() == 0)
//        {               
//            service.setService_id(((Integer) //  
//            getSqlMapClientTemplate().queryForObject("getServiceSeq",0)).intValue());
//        }

        return getSqlMapClientTemplate().update("insert" +         
                                            
object.getClass().getSimpleName(),object);
    }

It tries to insert '0' for service_id. However all works fine if I
uncomment those commented lines where I select sequence manually and
omit the selectKey from sql-map

Can someone indicate any direction where I should look?
TYA
Nicholoz Koka Kiknadze

Re: Trouble with oracle 10g selectKey

Posted by Koka <22...@gmail.com>.
Thanks Darek,

That worked fine. So there's typo in Spring in Action book (p. 169).
They the 'insert' using executeUpdate.

Nicholoz Koka Kiknadze

Re: Trouble with oracle 10g selectKey

Posted by Darek Dober <do...@op.pl>.
Try this (insert instead of update):

return getSqlMapClientTemplate().insert("insert" +

object.getClass().getSimpleName(),object);

Darek
----- Original Message ----- 
From: "Koka" <22...@gmail.com>
To: <us...@ibatis.apache.org>
Sent: Friday, August 05, 2005 7:32 AM
Subject: Trouble with oracle 10g selectKey


Wow, seems I'm dumb-minded today, can not make selectKey work....

Following the SQL-Maps-2.pdf I have:

<insert id='insertService' parameterClass='service'>
        <selectKey resultClass='int'>
            select services_seq.nextval as service_id from dual
        </selectKey>
insert into Services ( service_id,service_name)
values ( #service_id#,#service_name#)
</insert>

and dao (I'm using spring) looks like

public class ObjectDao extends SqlMapClientDaoSupport

public int insertObject(Object object) throws DataAccessException
    {
//        Service service = (Service) object;
//        if (service.getService_id() == 0)
//        {
//            service.setService_id(((Integer) //
//
getSqlMapClientTemplate().queryForObject("getServiceSeq",0)).intValue());
//        }

        return getSqlMapClientTemplate().update("insert" +

object.getClass().getSimpleName(),object);
    }

It tries to insert '0' for service_id. However all works fine if I
uncomment those commented lines where I select sequence manually and
omit the selectKey from sql-map

Can someone indicate any direction where I should look?
TYA
Nicholoz Koka Kiknadze