Skip to content

Instantly share code, notes, and snippets.

@recursivecodes
Created July 1, 2019 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save recursivecodes/5fdb044f1deb6364b7cb22effcafdfc8 to your computer and use it in GitHub Desktop.
Save recursivecodes/5fdb044f1deb6364b7cb22effcafdfc8 to your computer and use it in GitHub Desktop.
UserRepository.java
@RequestScoped
public class UserRepository {
    @PersistenceContext
    private static EntityManager entityManager;
    @Inject
    public UserRepository(UserProvider userProvider) {
        Map<String, Object> configOverrides = new HashMap<String, Object>();
        configOverrides.put("hibernate.connection.url", userProvider.getDbUrl());
        configOverrides.put("hibernate.connection.username", userProvider.getDbUser());
        configOverrides.put("hibernate.connection.password", userProvider.getDbPassword());
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("UserPU", configOverrides);
        entityManager = emf.createEntityManager();
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment