1

I'm using PostgreSQL in my java application without ORM. I want to go further and add Hibernate to my project. I have this sql query which I add to PreparedStatement() and it returns a number.

SELECT COUNT(pr.id) FROM prisoner pr
JOIN cell c ON c.id = pr.cell_id
JOIN prison p ON p.id = c.prison_id
WHERE p.id = ?

I'm new to Hibernate. How would you suggest me to rewrite this statement to work with Hibernate? Should I use HSQL, or criteria or query or something different ?

simon77
  • 89
  • 1
  • 9

1 Answers1

0

You can do it Either of following way.

1) Keep you query as it and use nativeSQL for hibernate.

hibernate native query, count

2) make model of all your join table and put hibernate query.

Community
  • 1
  • 1
Piyush Aghera
  • 965
  • 7
  • 13