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 James Johnson <jm...@hotmail.com> on 2006/07/19 23:51:20 UTC

update database followed by DO update

 

I have the following update SQL statement: update DOMAIN_OBJECT_TBL set SEQUENCE=SEQUENCE+1 where ID=#id#

 

Is it possible to have iBatis update the domain object, MyDomainObject, after executing this operation?

 

For instance, I would like to have code that gives the following:

//domain object's sequence is 1

myDomainObjectDao.incrementSequence(myDomainObject); // domain object 's sequence is now 2

Integer sequence = new Integer(myDomainObject.getSequence()); //sequence is 2

 

However, the code currently does the following because the domain object was not updated to reflect to the database update.

//domain object's sequence is 1

myDomainObjectDao.incrementSequence(myDomainObject); // domain object 's sequence is still 1

Integer sequence = new Integer(myDomainObject.getSequence()); //sequence is 1



I have the following statement sqlMap

<sqlMap>

<typeAlias type="com.example.MyDomainObject" alias="myDomainObject"/>

<resultMap class="MyDomainObject" id="result">

<result property="id" column="ID" />

<result property="sequence" column="SEQUENCE" />

</resultMap>

<update id="incrementSequence" parameterClass="myDomainObject">

update DOMAIN_OBJECT_TBL set SEQUENCE=SEQUENCE+1 where ID=#id#

</update>

</sqlMap>

Thanks in advance for your help.

Re: update database followed by DO update

Posted by Brandon Goodin <br...@gmail.com>.
You would have to perform a select and do that in your DAO. There would be
no reason for iBATIS to take up that kind of assumption. To iBATIS you are
updating the database. If you want to update your domain object you would
need to call a select of that value.

Brandon

On 7/19/06, James Johnson <jm...@hotmail.com> wrote:
>
>
>
> I have the following update SQL statement: update DOMAIN_OBJECT_TBL set
> SEQUENCE=SEQUENCE+1 where ID=#id#
>
>
>
> Is it possible to have iBatis update the domain object, MyDomainObject,
> after executing this operation?
>
>
>
> For instance, I would like to have code that gives the following:
>
> //domain object's sequence is 1
>
> myDomainObjectDao.incrementSequence(myDomainObject); // domain object 's
> sequence is now 2
>
> Integer sequence = new Integer(myDomainObject.getSequence()); //sequence
> is 2
>
>
>
> However, the code currently does the following because the domain object
> was not updated to reflect to the database update.
>
> //domain object's sequence is 1
>
> myDomainObjectDao.incrementSequence(myDomainObject); // domain object 's
> sequence is still 1
>
> Integer sequence = new Integer(myDomainObject.getSequence()); //sequence
> is 1
>
>
>
> I have the following statement sqlMap
>
> <sqlMap>
>
> <typeAlias type="com.example.MyDomainObject" alias="myDomainObject"/>
>
> <resultMap class="MyDomainObject" id="result">
>
> <result property="id" column="ID" />
>
> <result property="sequence" column="SEQUENCE" />
>
> </resultMap>
>
> <update id="incrementSequence" parameterClass="myDomainObject">
>
> update DOMAIN_OBJECT_TBL set SEQUENCE=SEQUENCE+1 where ID=#id#
>
> </update>
>
> </sqlMap>
>
> Thanks in advance for your help.
>