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


My problem is this:

I create this SP(in SQL Server 2000):

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

    select Id, Name
    from Person
    where Id = @id

This is the XML Map:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap
    PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"

<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"/>
    <!-- ///////////////Result Maps/////////////// -->
    <!-- ///////////////Procedues/////////////// -->
    <procedure id="create_person" resultMap="Person_Result" 
        {call create_person (#name#)}
    <!-- ///////////////Procedues/////////////// -->

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) {


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

View raw message