I have stored procedure in MS SQL Server
Code:
CREATE PROC dbo.insertData
@param1 nvarchar(11),
@param2 nvarchar(30),
@ID bigint OUTPUT
AS
BEGIN
INSERT INTO dbo.Adaptor (Col1, Col2) VALUES (@param1, @param2)
SET @ID = SCOPE_IDENTITY();
END
And I want to get this generated ID as output parameter in java.
I have created a mapping file
Code:
<sql-query name="insertData" callable="true">
<return alias="adaptor" class="MyClass">
<return-property name="id" column="ID" />
</return>
{ ? = call InsertData(:param1, :param2) }
</sql-query>
and trying to execute it from java
Code:
Query query = entityManager.createNamedQuery("insertData");
query.setParameter("param1", object);
query.setParameter("param2", getName());
// TODO try to use getSingleResult in tests
List result = query.getResultList();
But I have exception
Code:
java.sql.SQLException: Parameter #3 has not been set
If I remove ? = I got
j
Code:
ava.sql.SQLException: Procedure or function 'insertData' expects parameter '@ID', which was not supplied.
Has anyone any idea how code/mapping file should look like? Thanks in advance