Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Stored Procedure inside HQL query?  RSS feed

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hellow guys,

I have no Idea on how to do this in HQL
let's say in SQL I have this query :

where in getClientName is a stored procedure.


So, how do I do that in HQL?

Can we combine HQL query and stored procedure from native sql? I dont think it's possible.

Or so, can I create stored procedure in HQL and call it in my hibernate query?

So far what I'm doing is I just create a sub query so I can get the result in HQL:

this is my code for HQL :



But what I wanted to do is to create a stored procedure in hql to replace the sub query I used.
Is it possible?

I would appreciate any help!



 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think that you can call stored procedures with HQL but in your particular case you could use a formula mapping.
For example:
<property name="clientName" lazy="true">
<formula>
(select t.name from your_table t where t.foreign_key=id)
</formula>
</property>

In this particular case the "id" value will be the current object that your are loading id.
 
Cj Recto
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Atlast someone answered, I really need to know how to do this.

Thanks for that answer , and I was able to execute one. But I have another question,
That formula mapping is not a global access, it is only particular to a certain table.

What if I have many tables that has a column entityId, so it means that I have to create formula for every table?
I guess that is a tedious work. Is there no way to create a global access or query, (just like if you have stored proc in native sql)
so I won't need to create formula in all of my tables that have entityId.






 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!