For completeness, I am putting my HibernateUtils class here as well. {code:title=HibernateUtil.java|borderStyle=solid} public class HibernateUtil { private static SessionFactory sessionFactory; public static SessionFactory getSessionFactory() { if (sessionFactory == null) { try { Configuration configuration = new Configuration(); Properties settings = new Properties(); // settings.put(Environment.DRIVER, "com.mysql.cj.jdbc.Driver"); settings.put(Environment.DRIVER, "com.mysql.jdbc.Driver"); settings.put(Environment.URL, "jdbc:mysql://localhost:3306/hibernate-ix"); settings.put(Environment.USER, "my-user"); settings.put(Environment.PASS, "my-password"); settings.put(Environment.DIALECT, "org.hibernate.dialect.MySQL57Dialect"); settings.put(Environment.SHOW_SQL, "true"); configuration.setProperties(settings); configuration.addAnnotatedClass(Person.class); configuration.addAnnotatedClass(Child.class); ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() .applySettings(configuration.getProperties()) .build(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); } catch (Exception e) { e.printStackTrace(); } } return sessionFactory; } } {code} |