Untitled

 avatar
unknown
plain_text
3 years ago
1.1 kB
5
Indexable
public static org.hibernate.SessionFactory getSessionFactory() {
        try {
            if (sessionFactory == null) {

                final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
                        .configure() // configures settings from hibernate.cfg.xml
                        .build();
                sessionFactory = new MetadataSources(registry).addAnnotatedClass(StockAndInventory.class)
                        .addAnnotatedClass(Staff.class).addAnnotatedClass(Customer.class).addAnnotatedClass(Date.class)
                        .buildMetadata().buildSessionFactory();
                JOptionPane.showMessageDialog(null, "DB Connection Establised",
                        "CONNECTION STATUS", JOptionPane.INFORMATION_MESSAGE);

                return sessionFactory;
            }
        } catch (HibernateError ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(null, "Could not connection to database\n" + ex, "Connection Failure", JOptionPane.ERROR_MESSAGE);
        }


        return sessionFactory;
    }
Editor is loading...