javapostgresqlejb-3.0glassfish-3

Glassfish not picking up POSTGRES properties


I have EJB3 Entity bean which is to be saved in Postgres DB. I am using Glassfish 3 App server for deployment of the EJB.

When I make the call to EJB using my web layer, the DB call is made but Glassfish throws out the following exception

  javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=135;_ThreadName=Thread-1;|javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: could not inspect JDBC autocommit mode
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1215)
at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:635)
at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:589)
at com.cricinfo.session.service.PlayerService.getPlayer(PlayerService.java:41)

whose root cause is

Caused by: org.hibernate.exception.JDBCConnectionException: could not inspect JDBC autocommit mode
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:99)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
at org.hibernate.jdbc.JDBCContext.afterNontransactionalQuery(JDBCContext.java:296)
at org.hibernate.impl.SessionImpl.afterOperation(SessionImpl.java:595)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:1010)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:998)
at  org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:614)
... 96 more
Caused by: java.sql.SQLNonTransientConnectionException: No current connection.
at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at org.apache.derby.client.am.Connection.getAutoCommit(Unknown Source)
at com.sun.gjc.spi.base.ConnectionHolder.getAutoCommit(ConnectionHolder.java:307)
at org.hibernate.jdbc.ConnectionManager.isAutoCommit(ConnectionManager.java:212)
at org.hibernate.jdbc.JDBCContext.afterNontransactionalQuery(JDBCContext.java:287)
... 100 more
Caused by: org.apache.derby.client.am.SqlException: No current connection.

The connection to the Postgres DB is up and I can view the data using the pgAdmin tool. I can see the query being executed in the logs. From the logs we can see that Glassfish is using a derby client to fetch the connection.

Is there any configuration which I need to make in Glassfish ?

The persistence.xml is :

<persistence-unit name="PlayerApp" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>com.cricinfo.domain.Player</class>
    <properties>
         <property name="hibernate.connection.driver_class" value="org.postgresql.Driver" 
            /> <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" 
            /> <property name="hibernate.hbm2ddl.auto" value="update" /> <property name="hibernate.connection.url" 
            value="jdbc:postgresql://localhost:5432/PlayerAppDB" /> <property name="hibernate.show_sql" 
            value="true" /> <property name="hibernate.format_sql" value="true" /> <property 
            name="hibernate.connection.username" value="postgres" /> <property name="hibernate.connection.password" 
            value="postgres" /> 
    </properties>
</persistence-unit>

I am able to persist and get data by using a standalone class which directly uses the EntityManagerFactory.

EDIT : SOLUTION

I read about it a bit more and realised that I was doing a mistake in the persistence.xml . Now the persistence.xml looks like this :

<persistence-unit name="PlayerApp" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
     <jta-data-source>jdbc/DefaultDS</jta-data-source>
    <class>com.cricinfo.domain.Player</class>
</persistence-unit>

The transaction type was made to JTA and a Datasource was used instead of the connection properties.

I also logged into the Glassfish Admin console and configured JDBC Connection Pool and JDBC Resources from the tree CommonTasks-> Resources->JDBC

I am able to get the details now.


Solution

  • I read about it a bit more and realised that I was doing a mistake in the persistence.xml . Now the persistence.xml looks like this :

    <persistence-unit name="PlayerApp" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
         <jta-data-source>jdbc/DefaultDS</jta-data-source>
        <class>com.cricinfo.domain.Player</class>
    </persistence-unit>
    

    The transaction type was made to JTA and a Datasource was used instead of the connection properties.

    I also logged into the Glassfish Admin console and configured JDBC Connection Pool and JDBC Resources from the tree CommonTasks-> Resources->JDBC

    I am able to get the details now.