Hi!
I've been developing with Hibernate for a while and have just now been faced with this question,
What is the best approach to open the Session Factory? Open it when the application starts? Or for each set of instructions in the database?
Well, I ask this because I've been opening it for each set of instructions.
For example, when I want to list some data I do the following (Only map the necessary tables)
Code:
Configuration configuration = new Configuration()
.addAnnotatedClass(table1.class)
.addAnnotatedClass(table2.class)
.addAnnotatedClass(table3.class)
.configure();
serviceRegistry = new ServiceRegistryBuilder().applySettings(hibConfiguration.getProperties()).buildServiceRegistry();
sessionFactory = hibConfiguration.buildSessionFactory(serviceRegistry);
session = sessionFactory.withOptions().openSession();
In the Hibernate documentation they say
"A SessionFactory is set up once for an application". This would mean that all the tables will be added to the Session Factory on the application start right? Or will be set in the Hibernate.cfg.xml and for consequence will be loaded on the application start.
But does this applies to big databases? My application database has about 150 tables. Wouldn't it be to much heavy?
What do you advice?
Thanks in advance :)