permaculture playing cards*
The moose likes Object Relational Mapping and the fly likes Stored Procedure inside HQL query? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Stored Procedure inside HQL query?" Watch "Stored Procedure inside HQL query?" New topic
Author

Stored Procedure inside HQL query?

Cj Recto
Greenhorn

Joined: Mar 02, 2012
Posts: 26
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!



Bogdan Baraila
Ranch Hand

Joined: May 23, 2011
Posts: 43
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

Joined: Mar 02, 2012
Posts: 26
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.






 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stored Procedure inside HQL query?
 
Similar Threads
How Hibernate invokes Stored Procedures
How do I execute a SQL Server Stored Procedure with Hibernate?
Help required for hibernate query (HQL) calling stored procedure
Executing HQL queries along with SQL Queries
Help required for hibernate query (HQL) calling stored procedure