• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Stored Procedure inside HQL query?

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.






 
Are you okay? You look a little big. Maybe this tiny ad will help:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic