Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2013
    Posts
    108
    Rep Power
    0

    Default Session and SessionFactory

    In the hibernate examples I have seen session object is closed by calling session.close() , but sessionfactory is never closed. Is a sessionfactory object not needed to be closed?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default Re: Session and SessionFactory

    If you know what a SessionFactory does then you would understand why closing it makes no sense.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Join Date
    Aug 2013
    Posts
    108
    Rep Power
    0

    Default Re: Session and SessionFactory

    So, from the link I found this:


    public interface SessionFactory
    extends Referenceable, Serializable

    The main contract here is the creation of Session instances. Usually an application has a single SessionFactory instance and threads servicing client requests obtain Session instances from this factory.

    The internal state of a SessionFactory is immutable. Once it is created this internal state is set. This internal state includes all of the metadata about Object/Relational Mapping


    On what basis are you saying that session should be closed, while sessionfactory doesn't need to be closed?

    Please help me understand

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default Re: Session and SessionFactory

    A Session is a limited resource representing a connection to a database. That's why a Session needs to be closed, so it can be returned to the factory.
    A SessionFactory manages sessions and the underlying ORM. Why would you want to close it?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 2
    Last Post: 09-09-2012, 12:30 AM
  2. Replies: 1
    Last Post: 08-13-2007, 03:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •