How to point through Login, which database the system should connect to via Hibernate

0

I'm developing a JAVA system with JSF, PrimeFaces and Hibernate with Mysql database. In this system the user must inform the login the bank that wants to connect (User, password and bank). The problem is that when the user calls the Login screen Hibernate already starts the session manufacturing before the user reports the connection data. I would like to know if Hibernate has a way to only start the session factory after the user clicks Logar.

    
asked by anonymous 21.11.2017 / 21:02

1 answer

0
    private static SessionFactory criarFabricaDeSessoes(String nomeDoArquivo) {
    try {
        Configuration configuracao = new Configuration().configure(nomeDoArquivo);

        ServiceRegistry registro = new StandardServiceRegistryBuilder().applySettings(configuracao.getProperties())
                .build();

        SessionFactory fabrica = configuracao.buildSessionFactory(registro);

        return fabrica;
    } catch (Throwable ex) {
        System.err.println("A fábrica de sessões não pode ser criada." + ex);
        throw new ExceptionInInitializerError(ex);
    }
}
    
01.12.2017 / 18:07