In my project I use Hibernate. To interact with the database I use following class on server-side:
public class DatabaseWorker {
static SessionFactory sessionFactory = null;
static {
try{
sessionFactory = new Configuration().configure().buildSessionFactory();
}catch (Throwable ex) {
System.err.println("Failed to create sessionFactory object." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static void addToDatabase(String something) {
/...
}
}
When I call addToDatabase(String something) method for first time it takes a long time to execute because sessionFactory is need to be created. Is there any way to create sessionFactory before the first query?