Reputation: 11
I'm running a standalone EJB project in eclipse using Glashfish server. But it's throwing an error not related to the database I configured. I'm using PostgreSQL and hibernate as JPA provider. Note that I'm just deploying and running the application in eclipse.
Here's my persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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"
version="2.0">
<persistence-unit name="mypu">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/ejb" />
<property name="hibernate.connection.username" value="postgres" />
<property name="hibernate.connection.password" value="postgres" />
<!-- <property name="hibernate.show_sql" value="true"/> -->
<property name="hibernate.flushMode" value="FLUSH_AUTO" />
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
</persistence>
I think glassfish is using some default configuration and not able recognized what's in my persintence.xml
Error:
2017-06-25T14:50:24.835+0800|Info: HHH000204: Processing PersistenceUnitInfo [
name: mypu
...]
2017-06-25T14:50:25.868+0800|Warning: RAR5038:Unexpected exception while creating resource for pool DerbyPool. Exception : javax.resource.spi.ResourceAllocationException: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.
2017-06-25T14:50:25.869+0800|Warning: RAR5117 : Failed to obtain/create connection from connection pool [ DerbyPool ]. Reason : com.sun.appserv.connectors.internal.api.PoolingException: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.
2017-06-25T14:50:25.869+0800|Warning: RAR5114 : Error allocating connection : [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: connect.]
2017-06-25T14:50:25.869+0800|WARN: HHH000342: Could not obtain connection to query metadata : 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: connect.
2017-06-25T14:50:25.870+0800|Info: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2017-06-25T14:50:25.871+0800|Info: HHH000422: Disabling contextual LOB creation as connection was null
2017-06-25T14:50:25.907+0800|Info: HHH000397: Using ASTQueryTranslatorFactory
2017-06-25T14:50:25.949+0800|Info: HHH000228: Running hbm2ddl schema update
2017-06-25T14:50:25.951+0800|Info: HHH000102: Fetching database metadata
2017-06-25T14:50:26.953+0800|Warning: RAR5038:Unexpected exception while creating resource for pool DerbyPool. Exception : javax.resource.spi.ResourceAllocationException: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.
2017-06-25T14:50:26.953+0800|Warning: RAR5117 : Failed to obtain/create connection from connection pool [ DerbyPool ]. Reason : com.sun.appserv.connectors.internal.api.PoolingException: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.
2017-06-25T14:50:26.953+0800|Warning: RAR5114 : Error allocating connection : [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: connect.]
2017-06-25T14:50:26.954+0800|ERROR: HHH000319: Could not get database metadata
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: connect.
Upvotes: 1
Views: 227
Reputation: 691635
Extract from the JPA specifications (section 8.2.1.2):
transaction-type
The transaction-type attribute is used to specify whether the entity managers provided by the entity manager factory for the persistence unit must be JTA entity managers or resource-local entity managers. The value of this element is JTA or RESOURCE_LOCAL. A transaction-type of JTA assumes that a JTA data source will be provided — either as specified by the jta-data-source element or provided by the container. In general, in Java EE environments, a transaction-type of RESOURCE_LOCAL assumes that a non-JTA datasource will be provided. In a Java EE environment, if this element is not specified, the default is JTA. In a Java SE environment, if this element is not specified, the default is RESOURCE_LOCAL.
You have not specified the transaction-type, and you're running in a Java EE environment. So the default is JTA (which is the right thing to use).
Since it's JTA, the jta-data-source is used. But you haven't configured one, so the default datasource configured in the container is used.
You should configure a PostgreSQL connection pool (data source) in your Glassfish server, and use that datasource.
Upvotes: 1