ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eduardo Lobo <el...@inet.co.cr>
Subject Strange Problem..
Date Thu, 25 Aug 2005 18:35:35 GMT

Hi,

My problem is this:

I create this SP(in SQL Server 2000):

create procedure create_person
@name varchar(80)
as
begin
    declare @id int
   
    insert Person (Name)
    values (@name)
   
    Set @id = SCOPE_IDENTITY()

    select Id, Name
    from Person
    where Id = @id
end
GO


This is the XML Map:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap
    PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
    "http://www.ibatis.com/dtd/sql-map-2.dtd">

<sqlMap namespace="Person">
   
    <!-- ///////////////Type Aliases/////////////// -->
    <typeAlias alias="Map" type="java.util.Map"/>
    <typeAlias alias="Person" type="Person"/>
    <!-- ///////////////Type Aliases/////////////// -->
   
    <!-- ///////////////Result Maps/////////////// -->
    <resultMap id="Person_Result" class="Person">
        <result property="id" column="Id"/>
        <result property="name" column="Name"/>
    </resultMap>
    <!-- ///////////////Result Maps/////////////// -->
   
    <!-- ///////////////Procedues/////////////// -->
    <procedure id="create_person" resultMap="Person_Result" 
parameterClass="Map">
        {call create_person (#name#)}
    </procedure>
    <!-- ///////////////Procedues/////////////// -->
   
</sqlMap>


This is the java code:

SqlMapClient sqlMap = null;
        try {
            String file = "SQLConfigMap.xml";
            Reader reader = Resources.getResourceAsReader(file);
            sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
           
            HashMap params = new HashMap();
            params.put("name", "David");
            Object obj = sqlMap.queryForObject("create_person", params);
            System.out.println("create_person: " + obj);
           
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }


Results:

Finally when I print the result I got the new Record info,

Person: id = 1, name = David

That's fine, but when I check the Table there's not record...

But the strange is that it returns the mapped object with the new data, 
like if it was successfully inserted.

The "Id" field from the table Person is Identity (automatic sequential), 
and if I try to insert the record again then a I get the next "Id" 
(Person: id = 2, name = David), but again nothing is in the table..


Thanks for the help.

Eduardo Lobo






Mime
View raw message