When creating a DEV instance of postgreSQL on heroku, heroku create an environment variable named "DATABASE_URL" that contains url, user and password.
As we are in a cloud environment, your persistence.xml file should not contain any reference to a specific host, port or user/password account. It can change without any warning.
Unfortunately, this variable is not compliant with the JDBC format because HEROKU is not done just for the JAVA.
So we need to translate this generic URL into a valid JDBC URL and extract user password
You can found on the web a good example with Spring, but i've not found anything without it.
So here is a snippet of code that you can use in a ServletContextListener to initialize the EntityManagerFactory. (you will found it in org.mat.nounou.servlets.EntityManagerLoaderListener in this application).