I can not connect Jpa with PostgreSql at all

3

I'm trying to connect to postgresql , however, without success. My application will be a jsf application and so I'm using persistence.

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

    <persistence-unit name="comunicaVisual"
        transaction-type="RESOURCE_LOCAL">
        <jar-file>lib/postgresql-9.3-1101.jdbc3.jar</jar-file>
        <class>entys.Pessoa</class>
        <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
        <validation-mode>AUTO</validation-mode>
        <properties>
                <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
                <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/postgres" />
                <property name="javax.persistence.jdbc.user" value="testepg" />
                <property name="javax.persistence.jdbc.password" value="336445" />
                <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
                <property name="hibernate.connection.shutdown" value="true" />
                <property name="hibernate.hbm2ddl.auto" value="update" />
                <property name="hibernate.show_sql" value="false" />
                <property name="hibernate.format_sql" value="false" />

                <property name="hibernate.cache.use_query_cache" value="true"/>
                <property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory"/>
        </properties>
    </persistence-unit>

</persistence>

The error that is occurring is as follows. I hope someone has already gone through the situation.     

asked by anonymous 15.04.2014 / 03:56

1 answer

2

A generic connection failure error can have many causes. However, ideally you should look in the application logs to see if there are other error piles that have been written, but do not appear on the screen. Looking at logs is important but often ignored by developers.

However, I can list the most common causes of this type of error:

  • Database server is not started. You have installed it, but it is not running. Maybe the service is manually started.
  • Server does not accept remote connections. PostgreSQL has been installed on another machine and does not accept connections from other IPs. I'm not an expert on Postgre, but this is a common problem in MySQL.
  • Network lock. There is a firewall or proxy blocking the connection.
  • Configuration error. Although I can see your configuration, the correct one is to validate using some other program to see if any data has been improperly typed.
  • Missing driver. For some reason the application is not able to find or load the database driver. Is the jar really in the application? Could your application server be able to load the driver from there? You may need to refer to the server manual and perhaps install the jar as a module or place it inside the lib folder.
  • Incorrect driver version. I already helped a couple of people with a similar problem and the reason was that the driver version was either broken or outdated (the PostgreSQL installation was newer). The solution is to get the most up-to-date jar possible. Being with a lagged version can occur with existing projects or when someone copies a Maven dependency declaration from a site without querying the central repository.

Looking at the posted configuration, I saw that the configuration is used. jar-file to indicate the Postgre jar. This is wrong !!!

I do not know if it is the cause of the error, but this setting is to indicate the jar where the JPA entities are. This is used when the configuration xml is in a different package, eg in the case of JEE applications that contain a jar with EJBs.

Therefore, the most likely cause of the error is the lack of the jar in the correct place. Remember, Java automatically finds the jars that are in the WEB-INF\lib folder of a web application, in addition to the application server's library folders.

    
15.04.2014 / 17:07