I have replaced the HQL queries with that of SQL to shift back to plain JDBC from hibernate for many reasons. Now, I am not able to understand what SessionFactory in hibernate means and what should I replace it with in plain JDBC?Also, sessions in hibernate has a lot of configuration stuff involved.How do I deal with all these in plain JDBC?Please help.
Share
I’ll try and clear up your misunderstanding of a session factory and hopefully point you in the right direction.
The purpose of a session factory in JDBC is to handle connections to and from your database. When someone goes to your site and clicks a link that requires jdbc they will send out a request for a connection and the session factory will see that request. Then the session factory will either grab a connection from the pool or establish a new connection. This all happens in a matter of milliseconds.
Think of your database connections like cars on a lot and the session factory is the manager with the keys. When a user comes to your site and needs a connection they ask for 1 car. Then the manager will either give them a car out front that is sitting there started up and ready to go (connection in the pool) or will go out back and look for a new connection start it up and hand that car out (takes longer then getting a pool connection).
Then when the user is finished with the car (the connection) they give it back to the manager and he will decide if he should keep it out front and idle (in the pool) or bring it out back and turn it off. You can control where the session factory will look for the connections, and where he will place connections after they have been used by specifying attributes about your datasource (your database).
To gain a further understanding of the session factory you must first gain a further understanding of pooling within jdbc. So I would highly advice doing some google searches in that area to help clear some things up! Hope this points you in the right direction!