-->
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.  [ 4 posts ] 
Author Message
 Post subject: Simple++ problem with SqlServer2005 stored procedure
PostPosted: Mon Mar 23, 2009 6:20 am 
Newbie

Joined: Mon Mar 23, 2009 5:47 am
Posts: 5
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hi, guru! I'm new to hibernate, I read a lot of posts on stored procedure, still cannot gain how to access a simple stored procedure in java.

Hibernate version:3.3.1.GA


1,a simple table:
Code:
CREATE TABLE [dbo].[T_SEQUENCE](
   [Name] [varchar](100) NOT NULL,
   [SEQN] [int] IDENTITY(100,1) NOT NULL
) ON [PRIMARY]


2,a simple stored procedure:
Code:
ALTER Procedure [dbo].[SP_GetSeqn]
   @seqn int output
AS
Begin
   delete from t_sequence;
   insert into T_SEQUENCE(name) values('aaa');
   select @seqn = SCOPE_IDENTITY() ;
End


3,does this mapping correct?
Code:
<hibernate-mapping>
    <sql-query name="SP_GetSeqn" callable="true">
        <return-scalar type="int" column="seqn"/>
        {? = call SP_GetSeqn() }
    </sql-query>
</hibernate-mapping>


4,how to set output parameter? how to get the result?
Code:
Query  query =  session.getNamedQuery("SP_GetSeqn");
...


5,thank you very much!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 4:06 pm 
Regular
Regular

Joined: Mon Jan 05, 2009 6:42 pm
Posts: 99
Location: IL
I guess you don't need "? = " in your named query. Just do a call that should be good. When you execute the query make it to return the list of objects that you expect to.
Change your named query to:-
<hibernate-mapping>
<sql-query name="SP_GetSeqn" callable="true">
<return-scalar type="int" column="seqn"/>
{call SP_GetSeqn() }
</sql-query>

</hibernate-mapping>

Here is my other post for reference:-
http://forum.hibernate.org/viewtopic.ph ... highlight=

Hope this helps,
Latha.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 8:57 pm 
Newbie

Joined: Mon Mar 23, 2009 5:47 am
Posts: 5
latha1119 wrote:
I guess you don't need "? = " in your named query. Just do a call that should be good. When you execute the query make it to return the list of objects that you expect to.
Change your named query to:-
<hibernate-mapping>
<sql-query name="SP_GetSeqn" callable="true">
<return-scalar type="int" column="seqn"/>
{call SP_GetSeqn() }
</sql-query>

</hibernate-mapping>

Here is my other post for reference:-
http://forum.hibernate.org/viewtopic.ph ... highlight=

Hope this helps,
Latha.


Thank you very much. I've read your post before,my situation is little different from yours. Other posts are about input parameters and return ResultSet, while mine is return one scalar as output parameter.


Top
 Profile  
 
 Post subject: hi,anybody help!
PostPosted: Thu Mar 26, 2009 11:11 am 
Newbie

Joined: Mon Mar 23, 2009 5:47 am
Posts: 5
who can help me?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.