Skip to content Skip to sidebar Skip to footer

How To Execute Normal Sql Query In Hibernate Without Hql?

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

Solution 1:

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

Solution 2:

  • With JPA you can use entityManager.createNativeQuery(...)
  • With Hibernate there's session.createSQLQuery(...)

Post a Comment for "How To Execute Normal Sql Query In Hibernate Without Hql?"