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 Dp3 <do...@gmail.com> on 2005/05/04 19:06:36 UTC

selectKey & Oracle Database

Is there something special I need to do to get the selectKey tag to populate a
field?  I've been looking at this thing for quite a while now and cannot figure
out what I'm doing wrong.

Here is the entry in the sqlmap file:

<typeAlias alias="costCenter" type="edu.ohio.cost.domain.CostObject"/>

<insert id="createObject" parameterClass="costObject">
  <selectKey resultClass="int" keyProperty="costObjectId">
    select COST_OBJECT_S.nextval as costObjectId from dual
  </selectKey>
  insert into COST_OBJECT
 (COST_OBJECT_ID, COST_OBJECT_TYPE, STATUS, CREATED_BY, DATE_CREATED,
OBJECT_VERSION)
 values
 (#costObjectId#, #costObjectType#, #status#, #createdBy#, sysdate, 1)
</insert>

The CostObject.java file has a getter/setter for costObjectId (int).

The sequence (COST_OBJECT_S) is set up and works fine.

When I turn on logging, there is no reference to anything in the <selectKey..>
portion of the insert statement and the costObjectId is always 0.  I've tried to
change from the primitive int to the object, but the value of costObjectId is
null then.

I'm hoping I've just overlooked something small, but at this point I wouldn't
know what...

Any assistance would be greatly appreciated.
~Don

p.s. I'm using the 2.0.9 release of iBatis

Re: selectKey & Oracle Database

Posted by Clinton Begin <cl...@gmail.com>.
That should work. But I don't believe you've stated what the problem 
actually is. What is happening? Is there an exception? Is the costObjectId 
always being set to the same value? Is the sequence being incremented? Is 
the call to sqlMapClient.insert() returning the key propertly?

What's the problem?

Cheers,
Clinton


On 5/4/05, Dp3 <do...@gmail.com> wrote:
> 
> Is there something special I need to do to get the selectKey tag to 
> populate a
> field? I've been looking at this thing for quite a while now and cannot 
> figure
> out what I'm doing wrong.
> 
> Here is the entry in the sqlmap file:
> 
> <typeAlias alias="costCenter" type="edu.ohio.cost.domain.CostObject"/>
> 
> <insert id="createObject" parameterClass="costObject">
> <selectKey resultClass="int" keyProperty="costObjectId">
> select COST_OBJECT_S.nextval as costObjectId from dual
> </selectKey>
> insert into COST_OBJECT
> (COST_OBJECT_ID, COST_OBJECT_TYPE, STATUS, CREATED_BY, DATE_CREATED,
> OBJECT_VERSION)
> values
> (#costObjectId#, #costObjectType#, #status#, #createdBy#, sysdate, 1)
> </insert>
> 
> The CostObject.java file has a getter/setter for costObjectId (int).
> 
> The sequence (COST_OBJECT_S) is set up and works fine.
> 
> When I turn on logging, there is no reference to anything in the 
> <selectKey..>
> portion of the insert statement and the costObjectId is always 0. I've 
> tried to
> change from the primitive int to the object, but the value of costObjectId 
> is
> null then.
> 
> I'm hoping I've just overlooked something small, but at this point I 
> wouldn't
> know what...
> 
> Any assistance would be greatly appreciated.
> ~Don
> 
> p.s. I'm using the 2.0.9 release of iBatis
>