I am using JPA (EclipseLink) in a JSF project with Maven. During the runtime the following exception is thrown: No suitable driver found for jdbc:postgresql://localhost:5432/project
After that the GlassFish Server must be restarted.
Caused by: com.sun.appserv.connectors.internal.api.PoolingException: Connection could not be allocated because: No suitable driver found for jdbc:postgresql://localhost:5432/project?loginTimeout=0&socketTimeout=0&prepareThreshold=5&unknownLength=2147483647&loglevel=0&tcpkeepalive=false&binaryTransfer=true
at com.sun.enterprise.resource.pool.datastructure.RWLockDataStructure.addResource(RWLockDataStructure.java:103)
at com.sun.enterprise.resource.pool.ConnectionPool.addResource(ConnectionPool.java:282)
at com.sun.enterprise.resource.pool.ConnectionPool.createResourceAndAddToPool(ConnectionPool.java:1512)
at com.sun.enterprise.resource.pool.ConnectionPool.createResources(ConnectionPool.java:944)
at com.sun.enterprise.resource.pool.ConnectionPool.resizePoolAndGetNewResource(ConnectionPool.java:792)
at com.sun.enterprise.resource.pool.ConnectionPool.getResourceFromPool(ConnectionPool.java:760)
at com.sun.enterprise.resource.pool.ConnectionPool.getUnenlistedResource(ConnectionPool.java:632)
at com.sun.enterprise.resource.pool.ConnectionPool.internalGetResource(ConnectionPool.java:526)
at com.sun.enterprise.resource.pool.ConnectionPool.getResource(ConnectionPool.java:381)
at com.sun.enterprise.resource.pool.PoolManagerImpl.getResourceFromPool(PoolManagerImpl.java:245)
at com.sun.enterprise.resource.pool.PoolManagerImpl.getResource(PoolManagerImpl.java:170)
at com.sun.enterprise.connectors.ConnectionManagerImpl.getResource(ConnectionManagerImpl.java:360)
at com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:307)
... 53 more
I have tried everything. I looked for hours to solve the problem. My assumption is that the connection pool configuration is incorrect or that the Transaction Scoped (Container Managed) EntityManager does not close the connections properly.
Here are some code snippets from the project:
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="projectPU" transaction-type="JTA">
<jta-data-source>jdbc/project_customer_pool</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties/>
</persistence-unit>
</persistence>
glassfish-resources.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<jdbc-resource enabled="true"
jndi-name="jdbc/project_customer_pool"
object-type="user"
pool-name="project_customer_pool">
<description>Project Customer Pool</description>
</jdbc-resource>
<jdbc-connection-pool allow-non-component-callers="false"
associate-with-thread="false"
connection-creation-retry-attempts="0"
connection-creation-retry-interval-in-seconds="10"
connection-leak-reclaim="true"
connection-leak-timeout-in-seconds="15"
statement-timeout-in-seconds="8"
statement-leak-timeout-in-seconds="4"
connection-validation-method="auto-commit"
datasource-classname="org.postgresql.ds.PGConnectionPoolDataSource"
fail-all-connections="false"
idle-timeout-in-seconds="300"
is-connection-validation-required="false"
is-isolation-level-guaranteed="true"
lazy-connection-association="false"
lazy-connection-enlistment="false"
match-connections="false"
max-connection-usage-count="0"
max-pool-size="32"
max-wait-time-in-millis="60000"
name="project_customer_pool"
non-transactional-connections="false"
pool-resize-quantity="2"
res-type="javax.sql.ConnectionPoolDataSource"
steady-pool-size="8"
validate-atmost-once-period-in-seconds="0"
wrap-jdbc-objects="false">
<description>project db</description>
<property name="serverName" value="localhost"/>
<property name="portNumber" value="5432"/>
<property name="databaseName" value="project"/>
<property name="URL" value="jdbc:postgresql://localhost:5432/project"/>
<property name="User" value="admin"/>
<property name="Password" value="admin"/>
</jdbc-connection-pool>
</resources>
Database Access Object (DAO):
@Stateless
public class DAO implements IDAO, Serializable {
@PersistenceContext(unitName = "projectPU")
private EntityManager em;
// Example for a method
@Override
public Benutzer login(String email) {
if (email.isEmpty()) {
return null;
}
try {
TypedQuery<User> qu = em.createQuery("FROM User u WHERE u.email = :email AND u.valid_to IS null", User.class);
qu.setParameter("email", email);
return qu.getSingleResult();
} catch (Exception ex) {
System.err.println(ex.getMessage());
}
return null;
}
}
I hope someone can help me with that problem or has any idea how to solve it. I don`t know what to do anymore.
Thank you!