Connecting to a database through Hibernate in servlets

What is the best place in a servlet for Hibernate code returning a HibernateSessionFactory?

I saw many examples: some established a db connection in the maintenance methods. Others - use smth, like HibernateUtil (Singleton), which returns a HibernateSessionFactory.

I don’t know if HibernateUtil can be used in multi-threaded servlets?

+5
source share
2 answers

Normally, you should use the MVC framework in favor of Servlets directly, but that is not your question, and I'm going to suggest that you have a good reason to implement your own Servlets. To the answer ...

https://www.hibernate.org/hib_docs/v3/api/org/hibernate/SessionFactory.html:

.

SessionFactorys . a SessionFactory , . Environment.

, , SessionFactory s.

, , HibernateUtil , SessionFactory .

+6

(. ).

+1

All Articles