-->
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.  [ 10 posts ] 
Author Message
 Post subject: Problem accessing SQL Stored Procedure From .Net using hiber
PostPosted: Fri Dec 12, 2008 12:30 pm 
Newbie

Joined: Wed Dec 10, 2008 2:14 pm
Posts: 17
Hi,
I am calling a SQL Stored procedure from .net application using Hibernate object, but somehow its telling me " Named query not known".
I am not sure what's wrong I have done here.
Will really appreciate if someone can help me for this.
Herewith I am providing my Stored Procedure, my .hbm file and code to call it.

can someone pls tell me what's wrong in this?
Also, if possible, pls tell me how to set result in a list object.

Thanks in advance,


#########################################
MY STORED PROCEDURE :


ALTER PROCEDURE [dbo].[RulesDetails_Get]
(
@ELAID INT ,
@FamilyID INT ,
@GroupID INT ,
@SubGroupID INT ,
@ItemComponentID INT ,
@ComponentID INT
)
AS
BEGIN

SELECT
QtyAlreadyOrdered_Component,
QtyAlreadyOrdered_Family,
QtyAlreadyOrdered_Group ,
QtyAlreadyOrdered_SubGroup,
QtyAlreadyOrdered_ELA ,

MaxQtyAllowed_Component ,
MaxQtyAllowed_Family ,
MaxQtyAllowed_Group ,
MaxQtyAllowed_SubGroup ,
MaxQtyAllowed_ELA ,

QtyBalanceAvailable_Component,
QtyBalanceAvailable_Family,
QtyBalanceAvailable_Group,
QtyBalanceAvailable_SubGroup,
QtyBalanceAvailable_ELA
FROM
MyTable1
WHERE
ELAID = @ELAID
AND
FamilyID = @FamilyID



#########################################


#########################################
MY .HBM FILE FOR THIS STORED PROCEDURE:
<?xml version="1.0" encoding="utf-8" ?>
<!-- Generated by MoreGen 28-Apr-2008 11:27:28 -->
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" >


<sql-query name="RulesDetails_Get" callable="true">
<return class="RulesDetails_Get">
<return-property name="QtyAlreadyOrdered_Component" column="QtyAlreadyOrdered_Component"></return-property>
<return-property name="QtyAlreadyOrdered_Family" column="QtyAlreadyOrdered_Family"></return-property>
<return-property name="QtyAlreadyOrdered_Group" column="QtyAlreadyOrdered_Group"></return-property>
<return-property name="QtyAlreadyOrdered_SubGroup" column="QtyAlreadyOrdered_SubGroup"></return-property>
<return-property name="QtyAlreadyOrdered_ELA" column="QtyAlreadyOrdered_ELA"></return-property>

<return-property name="MaxQtyAllowed_Component" column="MaxQtyAllowed_Component"></return-property>
<return-property name="MaxQtyAllowed_Family" column="MaxQtyAllowed_Family"></return-property>
<return-property name="MaxQtyAllowed_Group" column="MaxQtyAllowed_Group"></return-property>
<return-property name="MaxQtyAllowed_SubGroup" column="MaxQtyAllowed_SubGroup"></return-property>
<return-property name="MaxQtyAllowed_ELA" column="MaxQtyAllowed_ELA"></return-property>

<return-property name="QtyBalanceAvailable_Component" column="QtyBalanceAvailable_Component"></return-property>
<return-property name="QtyBalanceAvailable_Family" column="QtyBalanceAvailable_Family"></return-property>
<return-property name="QtyBalanceAvailable_Group" column="QtyBalanceAvailable_Group"></return-property>
<return-property name="QtyBalanceAvailable_SubGroup" column="QtyBalanceAvailable_SubGroup"></return-property>
<return-property name="QtyBalanceAvailable_ELA" column="QtyBalanceAvailable_ELA"></return-property>


</return>
{ call RulesDetails_Get(?,:ELAID, ?,:FamilyID, ?,:GroupID, ?,:SubGroupID, ?,:ItemComponentID, ?,:ComponentID) }
</sql-query>

</hibernate-mapping>



#########################################


#########################################
MY CODE TO CALL STORED PROCEDURE :
NHibernate.ISession hibSession = null;

hibSession = getHibSession();


IQuery q = hibSession.GetNamedQuery("RulesDetails_Get");

q.SetParameter("ELAID", 7);
q.SetParameter("FamilyID", 28);
q.SetParameter("GroupID", 79);
q.SetParameter("SubGroupID", 219);
q.SetParameter("ItemComponentID", 584);
q.SetParameter("ComponentID", 563);

q.List();

#########################################


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 12, 2008 12:58 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Is the mapping file marked as "Embedded Resource" ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 12, 2008 1:14 pm 
Newbie

Joined: Wed Dec 10, 2008 2:14 pm
Posts: 17
Sorry, I missed that. But once I did that, its telling me "The 'callable' attribute is not declared.",

I am still could not get the exact problem.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 12, 2008 1:33 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Where did you get the "callable" from. NH 1.2 only has a flush-mode attribute defined.

You know that you can use IntelliSense with the mappings ? The schema definitions are part of the nhibernate source code. Copy those to

C:\Program Files\Microsoft Visual Studio 8\Xml\Schemas

or wherever your VS is installed.

Source code is here: http://sourceforge.net/project/showfiles.php?group_id=73818&package_id=73969

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 12, 2008 2:02 pm 
Newbie

Joined: Wed Dec 10, 2008 2:14 pm
Posts: 17
Hi, Really thanks for your quick reply.

I copied "nhibernate-configuration" and "nhibernate-mapping" xml schema files to "C:\Program Files\Microsoft Visual Studio 8\Xml\Schemas"

but still getting same error.

Do you see anything wrong in defined .hbm file to call SP?
I mean I have doubt that I may have missed something in .hbm file or may be something wrong calling it.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 12, 2008 2:36 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Is it still this error "The 'callable' attribute is not declared." ? I think that this attribute is not defined in the schema, so just remove it.

Btw the schema definitions only help to validate the mappings syntactically, they don't fix any error.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 12, 2008 2:49 pm 
Newbie

Joined: Wed Dec 10, 2008 2:14 pm
Posts: 17
o grt. Ya, I removed that parameter and it went through getsession.
But I am getting one more error on

q.List();

Error is "Not all named parameters have been set: [] [{ call RulesDetails_Get(?,?,?,?,?,?) }]"


Can you tell me by looking at my code if I wrote correct syntex to call this Stored Procedure with Passing 6 parameters?

Again, this is how I call my SP.
{ call RulesDetails_Get (?,:ELAID, ?,:FamilyID, ?,:GroupID, ?,:SubGroupID, ?,:ItemComponentID, ?,:ComponentID) }

And here is my code in .net to call it.
IQuery q = hibSession.GetNamedQuery("RulesDetails_Get");

q.SetParameter("ELAID", 7);
q.SetParameter("FamilyID", 28);
q.SetParameter("GroupID", 79);
q.SetParameter("SubGroupID", 219);
q.SetParameter("ItemComponentID", 584);
q.SetParameter("ComponentID", 563);

q.List();


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 12, 2008 3:16 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
{ call RulesDetails_Get(?,:ELAID, ?,:FamilyID, ?,:GroupID, ?,:SubGroupID, ?,:ItemComponentID, ?,:ComponentID) }

You have to either use named parameters or ? !

{ call RulesDetails_Get(:ELAID, :FamilyID, :GroupID, :SubGroupID,:ItemComponentID, :ComponentID) }

or

{ call RulesDetails_Get(?,?,?,?,?,?) }

If you use ? than you have to call SetParameter without the name.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 12, 2008 3:35 pm 
Newbie

Joined: Wed Dec 10, 2008 2:14 pm
Posts: 17
really Thanks,


Now I am getting error "No persister for: ELADAO.RulesDetails_Get, ELADAO". ("ELADAO.RulesDetails_Get, ELADAO" is my class name.

It seems like I am really closed to get it.
I am putting my improved code again, so if you can help me for error "No persister for: ELADAO.RulesDetails_Get, ELADAO", I will be thankful for that.


<?xml version="1.0" encoding="utf-8" ?>
<!-- Generated by MoreGen 28-Apr-2008 11:27:28 -->
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" >


<sql-query name="RulesDetails_Get" >
<return alias="RulesDetails_Get" class="ELADAO.RulesDetails_Get, ELADAO">
<return-property name="QtyAlreadyOrdered_Component" column="QtyAlreadyOrdered_Component"></return-property>
<return-property name="QtyAlreadyOrdered_Family" column="QtyAlreadyOrdered_Family"></return-property>

</return>


{ call RulesDetails_Get(:ELAID, :FamilyID, :GroupID, :SubGroupID, :ItemComponentID, :ComponentID) }
</sql-query>

</hibernate-mapping>



METHOD TO CALL IT:

hibSession = getHibSession();


IQuery q = hibSession.GetNamedQuery("RulesDetails_Get");

q.SetParameter("ELAID", 7);
q.SetParameter("FamilyID", 28);
q.SetParameter("GroupID", 79);
q.SetParameter("SubGroupID", 219);
q.SetParameter("ItemComponentID", 584);
q.SetParameter("ComponentID", 563);

IList results = q.List();


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 13, 2008 7:21 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
I'm not sure, but it probably means that you do not have a mapping vor class ELADAO.RulesDetails_Get.

_________________
--Wolfgang


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