• 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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.






 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!