A Hibernate Session is stored in a static field and shared across web requests. What is wrong with this design?

Practice this question from Quiz: Hibernate ORM, with options and an explanation.

Question

A Hibernate Session is stored in a static field and shared across web requests. What is wrong with this design?

Option A — Correct answer

Session is not thread-safe and should be short-lived

Share SessionFactory, not Session.

Option B

SessionFactory is never thread-safe

Option C

Hibernate does not support transactions

Option D

Entity classes cannot have IDs

Explanation

Session is not thread-safe and should be short-lived; SessionFactory is the thread-safe shared object.

Quiz: Hibernate ORM

All questions · Previous question · Next question

Open on QuizMaker