I am trying to connect to DB in a servlet using Hibernate.I have read that we can use either hibernate.cfg.xml or hibernate.properties file for configuration of session.For me i
Remove .configure()
if you are using hibernate.properties
. Below code is
HibernateUtil
session factory implementation.
private static SessionFactory buildSessionFactory() {
try {
Configuration configuration = new Configuration();
ServiceRegistry serviceRegistry
= new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build();
configuration.addAnnotatedClass(LookUpModel.class);
return configuration
.buildSessionFactory(serviceRegistry);
}catch(Exception e) {
e.printStackTrace();
throw new RuntimeException("There is issue in hibernate util");
}
}
hibernate.properites file
hibernate.connection.driver_class = com.mysql.jdbc.Driver
hibernate.connection.url = jdbc:mysql://localhost:3306/test
hibernate.connection.username = root
hibernate.connection.password = passsword
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=1800
hibernate.c3p0.max_statements=50
hibernate.dialect = org.hibernate.dialect.MySQL5Dialect