users@jersey.java.net

CMP and Jersey

From: Comerford, Sean <Sean.Comerford_at_espn3.com>
Date: Tue, 1 Dec 2009 21:57:36 +0000

I have a JPA (w/ Hibernate) connection to a SQL server DB configured. I have
a bunch of Jersey resources configured and successfully working by getting
an EntityManagerFactory directly via a call to
Persistence.createEntityManagerFactory(³foo²).

Now I¹m trying to convert these resources to have Glassfish inject the EMF
as is done in the bookmark Jersey sample... i.e:

@PersistenceUnit(unitName = "NbaJpa")
EntityManagerFactory entityManagerFactory = null;

I have changed my web.xml to use the Jersey ServletAdaptor (as shown in the
bookmark example) and changed the params as appropriate for data source.

I¹m guessing I¹m missing something completely brain dead but as far as I can
tell, the only difference at this point with my project and the bookmark
example is I¹m NOT using a JTA data source. But when I try to access the
Jersey resource that uses CMP I get the exception shown below. For what it¹s
worth, my other resources that still call Persistence.createEMF to get the
EMF directly work fine.

Any ideas what I¹ve missed? It seems to be trying to connect to localhost
1527 (the derby port I believe) for unknown reasons. My one and only
persistence unit is configured as a JDBC resource to talk to a remote host
on port 1433 (the SQL server port).

javax.persistence.PersistenceException:
org.hibernate.exception.GenericJDBCException: Cannot open connection
... Blah blah blah ....
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.
    at com.sun.gjc.spi.base.DataSource.getConnection(DataSource.java:115)
    at
org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnect
ion(InjectedDataSourceConnectionProvider.java:46)
    at
org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:4
46)
    ... 65 more


-- 
Sean Comerford, Software Engineer
ESPN.com Site Architecture Group
Office: 860.766.6454    Cell: 860.329.5842