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: Question about named queries
PostPosted: Thu Oct 16, 2008 12:03 pm 
Newbie

Joined: Mon Oct 13, 2008 4:40 am
Posts: 3
Hello everybody,

i´d like to use named queries in my project because I have a stored procedure i´d like to call.

Right now my code looks like this:

Code:
Query query = em.createNativeQuery("SELECT stored_procedure(?,?,?) from DUAL");
      query.setParameter(1, userId);
      query.setParameter(2, value);
      query.setParameter(3, date);
String result = (String) query.getSingleResult();



I´d like to call this stored procedure by a named query.

I know that I can define it in a mapping file like this:

Code:
<hibernate-mapping >
   <sql-query name="test">
      <return alias="testString" type="java.lang.String" />
      { SELECT stored_procedure(?,?,?) from DUAL }
   </sql-query>
</hibernate-mapping>


But somehow my stored procedure isn´t found - who could help me ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 17, 2008 2:25 pm 
Newbie

Joined: Mon May 05, 2008 10:34 am
Posts: 11
Location: Houston, TX
You cannot SELECT from a stored procedure, the syntax is EXEC sp_YadaYada

From NHibernate Docs:

<sql-query name="selectAllEmployments_SP">
<return alias="emp" class="Employment">
<return-property name="employee" column="EMPLOYEE"/>
<return-property name="employer" column="EMPLOYER"/>
<return-property name="startDate" column="STARTDATE"/>
<return-property name="endDate" column="ENDDATE"/>
<return-property name="regionCode" column="REGIONCODE"/>
<return-property name="id" column="EID"/>
<return-property name="salary">
<return-column name="VALUE"/>
<return-column name="CURRENCY"/>
</return-property>
</return>
exec selectAllEmployments
</sql-query>


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.