Wednesday, 20 April 2016

What is a SessionFactory ? Is it a thread-safe object ?


SessionFactory is Hibernate 's concept of a single datastore and is threadsafe so that many threads can access it concurrently and request for sessions and immutable cache of compiled mappings for a single database.

A SessionFactory is usually only built once at startup.

SessionFactory should be wrapped in some kind of singleton so that it can be easily accessed in an application code.

SessionFactory sessionFactory = 
        new Configuration().configure().buildSessionfactory();

No comments:

Post a Comment

Note: only a member of this blog may post a comment.