When I use Hibernate as a persistence provider, the construct
@PersistenceContext(unitName = "bigproject", name = "bigproject")
private EntityManager em;
does something (as the em field is not null) but it any attempt to use if raises
the following exception:
Caused by: java.sql.SQLException: Error in allocating a connection. Cause:
Connection could not be allocated because: java.net.ConnectException : Error
connecting to server localhost on port 1527 with message Connection refused.
... 71 more
Here we see a wrong port, 1527 (Postgresql runs on its default 5432).
Hibernate persistence with Postgresql works flawlessly if introduced in the
EntityManagerFactory factory = Persistence
em = factory.createEntityManager();
Same peristence.xml is used in both cases. Postgresql is running on a local host
and is both functional and reachable, as the bean using the second version of
the code works at the same deployment.