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
LVL 7
gudii9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

girionisCommented:
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.
0
gudii9Author Commented:
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.
0
girionisCommented:
if something is threadsadte do we need to create ourselves single instance(does not meaning of threadsafe takes care of that by itself)

If you don't create an instance you can't use an object, so yes, you need to create the instance first.

can you please advise on Internal state immutable and thread safety and single instance relationship. I am not cear on this.

I think the best you can do is to read "Effective Java" by Joshua Bloch, it has a very nice chapter on immutable objects. And also "Java Concurrency in practice" by Brian Goetz, it also has a very detailed chapter on concurrency and immutable objects.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.