Hibernate session vs DB connection

Depends what kind of query you are executing. EntityManager.find will look into the first level cache first, but a query will always hit the database unless you configured second level caching and query caching.

I would suggest you don’t open a transaction if this is a read only use case, as the transaction commit/rollback will acquire the connection.

2 Likes