I should add that another big difference is my DB connection is configured
as a JDBC resource on the container. So my persistence.xml has
<non-jta-data-source>jdbc/SportwareNBA</non-jta-data-source> and some
connection properties (for 2nd level caching) but there is NO JDBC url
property in my persistence.xml directly.
It seems like maybe the injection on the Jersey resource can¹t find the JDBC
url properties and is therefore using some defaults?
On 12/1/09 4:57 PM, "Comerford, Sean" <Sean.Comerford_at_espn3.com> wrote:
> 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.getConnectio
> n(InjectedDataSourceConnectionProvider.java:46)
> at
>
org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446>
)
> ... 65 more
>
--
Sean Comerford, Software Engineer
ESPN.com Site Architecture Group
Office: 860.766.6454 Cell: 860.329.5842