-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Get Sql Server stored procedure output in Hibernate
PostPosted: Mon Jun 17, 2013 3:36 am 
Newbie

Joined: Mon Jun 17, 2013 3:26 am
Posts: 1
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


Top
 Profile  
 
 Post subject: Re: Get Sql Server stored procedure output in Hibernate
PostPosted: Wed Jun 19, 2013 3:50 am 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
It's just introduce in JPA 2.1

Please refer to
https://blogs.oracle.com/arungupta/entry/jpa_2_1_early_draft


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.