0

I have a pretty complex Join query to select few items from DB, and it doesn't involve any Update required back to this table. Which is why, I don't want to use the HQL (Hibernate Query Language, instead I want to execute as a simple SQL query.

Is that possible to execute a Normal SQL - Join query which involves 3 different tables in hibernate? I use Java - Struts framework.

If you say it is not possible then I have to stick to HQL and I would post here the query for which I would need your help in writing down HQL based class(tables) creations and HQL based Query string.

Also, if you could please give me an example query with couple or 3 table Joins and how to set the Parameters for the SQL.

2 Answers 2

2

from below line of code you can use any Query with hibernate

its call Native SQL

session.createSQLQuery("SELECT * FROM table as a join table1 as b  on a.id = b.id ").list();

for more help go here

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks Nirav. I am seeing problem while setting up Parameters. Do you have idea about assigning parameters for the SQL query? Can you show me some example on how parameters need to be set?
@Gersh :: which kind of parameter can you provide your Query so that i can help you
Please see this link and try to suggest your opinion there. link
I have used your opinion but the query gets failed at execution. Please the above link I posted.
@gersh :: check link i gave answer hope will help you
|
1
  • With JPA you can use entityManager.createNativeQuery(...)
  • With Hibernate there's session.createSQLQuery(...)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.