I’ve deployed a small application to AWS EC2, I keep getting this error:
[pool-2-thread-1] DEBUG org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl - Connection pool now considered primed; min-size will be maintained
There are few mentions of this error in SOF, but not very similar to my case.
And the application does not proceed after that point.
Thanks Vlad,
What do you collect from being able to run the same code on the local machine but not on AWS EC2?
both show the same error above, but the local machine carry on with running the rest of the code.
this happens at this method :
public List<BroadcastItem> getSent() {
List<BroadcastItem> sentItems = new ArrayList<>();
try (Session session = HibernateUtil.getSessionFactory().openSession()) {
sentItems = session.createQuery("from BroadcastItem where sent = true").list();
} catch (Exception e) {
e.printStackTrace();
}
return sentItems;
}
HibernateUtil being this class:
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
System.err.println("SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
private HibernateUtil() {
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
Because it’s a fairly simple application, looking at the [pool-2-thread-1] part in the DEBUG log makes me think that there’s also thread/connection issue? and also application does not exit when I run it from within my IDE, I have to terminate it manually.
Is there a way that you suggest to debug this further? or you still recommend switching to HikariCP or one of the others?
Thanks Vlad,
Your answer led me to do more reading on the advantages of using Hibernate with Spring and EJB.
But for the sake of completing this small project though, I’ve tried to close the factorySession, this causes the application to exit completely, before the method completes it’s work.
that’s when using: HibernateUtil.getSessionFactory().close()
Is this the right use for this particular case?
As for closing the sessions, in my method above I’m using try with resources to close the session.
To terminate Hibernate you have to close the SessionFactory.
Otherwise managed connection pools will do their job by design: try and keep a pool of connections open to reuse. This is essential to achieve good performance.