You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by Gladys Gonzalez <gg...@softekpr.com> on 2006/02/08 20:18:58 UTC
Output Parameters in Stored Procedures
Hi,
I want to return a value from a stored Procedure with Ibatis. I did all
the steps indicated in the documentation but I can't get the value. Can
you please send me a sample code to do this. I'm including my code for
your review.
<parameterMap id="NewsInsert-Params">
<parameter property="NewsId" column="OUT_NEWS_ID"
direction="Output" dbType="Numeric"/>
<parameter property="Status" column="STATUS" />
<parameter property="EmpId" column="EMP_ID" />
<parameter property="DeptCode" column="DEPT_CODE" />
<parameter property="NewsDate" column="NEWS_DATE" />
<parameter property="Description" column="DESCRIPTION" />
<parameter property="NewsText" column="NEWS_TEXT" />
<parameter property="EffectiveFrom" column="EFFECTIVE_FROM" />
<parameter property="EffectiveTo" column="EFFECTIVE_TO" />
<parameter property="TimeFrom" column="TIME_FROM" />
<parameter property="TimeTo" column="TIME_TO" />
<parameter property="Type" column="TYPE" />
<parameter property="DivisionCode" column="DIVISION_CODE" />
<parameter property="ModificationId" column="MODIFICATION_ID" />
<parameter property="ModificationName" column="MODIFICATION_NAME"
/>
<parameter property="TrnCode" column="TRN_CODE" />
<parameter property="NewsAuditor.SigAction"
resultMapping="NewsMap.AuditSignature.SigAction" />
<parameter property="NewsAuditor.SigMeaning"
resultMapping="NewsMap.AuditSignature.SigMeaning" />
<parameter property="NewsAuditor.KeyId"
resultMapping="NewsMap.AuditSignature.KeyId" />
<parameter property="NewsAuditor.KeyUserId"
resultMapping="NewsMap.AuditSignature.KEYUSERID" />
</parameterMap>
<procedure id="InsertNews" parameterMap="NewsInsert-Params"
resultClass="News">
SP_NEWS_INSERT
</procedure>
'This is a Method in my Class NewsMap, it is supposed to return an
object representing the News entity with the NewsId filled
Public Overloads Function Insert(ByVal objNews As
Domain.Maintenance.News) As Domain.Maintenance.News Implements
Interfaces.Maintenance.INews.Insert
Return ExecuteQueryForObject("InsertNews", objNews)
End Function
'Here is the implementation but does not return nothing
objNewsDomain = objNewsMap.Insert(CreateObject("I"))
I would appreciate any help you could give me.
Regards,
Gladys
Re: Output Parameters in Stored Procedures
Posted by Gilles Bayon <ib...@gmail.com>.
You should use ExecuteInsert
/// <summary>
/// Execute an insert statement. Fill the parameter object with
/// the ouput parameters if any, also could return the insert generated key
/// </summary>
/// <param name="session">The session</param>
/// <param name="parameterObject">The parameter object used to fill the
statement.</param>
/// <returns>Can return the insert generated key.</returns>
object ExecuteInsert(IDalSession session, object parameterObject );
Here a sample from Nunit test
Category category = new Category();
category.Name = "Mapping object relational";
sqlMap.Insert("InsertCategoryViaStoreProcedure", category);
Assert.AreEqual(1, category.Id );
<procedure id="InsertCategoryViaStoreProcedure" parameterMap="insert-params"
>
ps_InsertCategorie
</procedure>
<parameterMap id="insert-params">
<parameter property="Id" column="Category_Id" dbType="Int" />
<parameter property="Name" column="Category_Name"/>
<parameter property="Guid" column="Category_Guid" dbType="UniqueIdentifier"
/>
</parameterMap>
it is for SQL Server but you will find the same example for Oracle