Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

hibernate singleton static instance

hI,


I am reading as below

SessionFactory in hibernate are thread safe.
So it is recommended to have only copy of  Sessionfactory.
Whereas Hibernate Session are not thread safe and Session can have many instances.
To achieve this use of Singleton by creating static instance of Sessionfactory and then create static method returning SessionFactory instace.


I am not clear on above sentences. what exactly it means. What is the role of singleton and static in hibernate.

Please advise
Any links resources ideas highly appreciated. Thanks in advance
Avatar of girionis
girionis
Flag of Greece image

It simply means that you should only have one instance of SessionFactory, and then use this instance to create Session objects. Since SessionFactory's internal state is immutable (and thus inherently thread safe), many threads can access it simultaneously and ask for a Session object without problem.
Avatar of gudii9

ASKER

if something is threadsadte do we need to create ourselves single instance(does not meaning of threadsafe takes care of that by itself)

>>>Since SessionFactory's internal state is immutable (and thus inherently thread safe),


can you please advise on Internal state immutable and thread safety and single instance relationship. I am not cear on this.
ASKER CERTIFIED SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial