persistence@glassfish.java.net

Error with Spring, Hibernate JPA and GlassFish

From: Guillaume Bilodeau <gbilodeau_at_yahoo.com>
Date: Wed, 4 Oct 2006 00:07:16 -0700 (PDT)

Hi all,

Once more I'm asking for your help. One of our applications is using Spring
2.0 (still RC1, didn't upgrade to final yet) and Hibernate EntityManager as
the JPA provider. It's packaged as a WAR file and deployed to GlassFish.

We're getting the following error upon deploying:

[code]
[#|2006-10-04T10:22:42.816+0400|WARNING|sun-appserver-pe9.0|javax.enterprise.system.container.web|_ThreadID=14;_ThreadName=Thread-32;_RequestID=0bbadd76-dd9f-4fea-974a-4fddddd5a04d;|
Internal Exception: java.sql.SQLException: Error in allocating a connection.
Cause: Connection could not be allocated because:
java.security.PrivilegedActionException : Error opening socket to server
localhost on port 1527 with message : nullError Code: 0
Local Exception Stack:
Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2006.4 (Build
060412)): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Error in allocating a connection.
Cause: Connection could not be allocated because:
java.security.PrivilegedActionException : Error opening socket to server
localhost on port 1527 with message : nullError Code: 0
        at
oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:289)
        at
oracle.toplink.essentials.jndi.JNDIConnector.connect(JNDIConnector.java:135)
        at
oracle.toplink.essentials.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:167)
        at
oracle.toplink.essentials.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:537)
        at
oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:193)
        at
oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.createContainerEntityManagerFactory(EntityManagerFactoryProvider.java:168)
        at
com.sun.enterprise.server.PersistenceUnitLoaderImpl.load(PersistenceUnitLoaderImpl.java:195)
        at
com.sun.enterprise.server.PersistenceUnitLoaderImpl.load(PersistenceUnitLoaderImpl.java:106)
        at
com.sun.enterprise.web.WebModuleListener.loadPersistenceUnits(WebModuleListener.java:175)
        at
com.sun.enterprise.web.WebModuleListener.lifecycleEvent(WebModuleListener.java:152)
        at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:130)
        at
org.apache.catalina.core.StandardContext.start(StandardContext.java:4673)
        at com.sun.enterprise.web.WebModule.start(WebModule.java:292)
        at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:833)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:817)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:659)
        at
com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1468)
        at
com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1133)
        at
com.sun.enterprise.server.WebModuleDeployEventListener.moduleDeployed(WebModuleDeployEventListener.java:171)
        at
com.sun.enterprise.server.WebModuleDeployEventListener.moduleDeployed(WebModuleDeployEventListener.java:275)
        at
com.sun.enterprise.admin.event.AdminEventMulticaster.invokeModuleDeployEventListener(AdminEventMulticaster.java:954)
        at
com.sun.enterprise.admin.event.AdminEventMulticaster.handleModuleDeployEvent(AdminEventMulticaster.java:941)
        at
com.sun.enterprise.admin.event.AdminEventMulticaster.processEvent(AdminEventMulticaster.java:448)
        at
com.sun.enterprise.admin.event.AdminEventMulticaster.multicastEvent(AdminEventMulticaster.java:160)
        at
com.sun.enterprise.admin.server.core.DeploymentNotificationHelper.multicastEvent(DeploymentNotificationHelper.java:296)
        at
com.sun.enterprise.deployment.phasing.DeploymentServiceUtils.multicastEvent(DeploymentServiceUtils.java:203)
        at
com.sun.enterprise.deployment.phasing.ServerDeploymentTarget.sendStartEvent(ServerDeploymentTarget.java:285)
        at
com.sun.enterprise.deployment.phasing.ApplicationStartPhase.runPhase(ApplicationStartPhase.java:119)
        at
com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:95)
        at
com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:871)
        at
com.sun.enterprise.deployment.phasing.PEDeploymentService.start(PEDeploymentService.java:541)
        at
com.sun.enterprise.deployment.phasing.PEDeploymentService.start(PEDeploymentService.java:585)
        at
com.sun.enterprise.admin.mbeans.ApplicationsConfigMBean.start(ApplicationsConfigMBean.java:719)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at
com.sun.enterprise.admin.MBeanHelper.invokeOperationInBean(MBeanHelper.java:353)
        at
com.sun.enterprise.admin.MBeanHelper.invokeOperationInBean(MBeanHelper.java:336)
        at
com.sun.enterprise.admin.config.BaseConfigMBean.invoke(BaseConfigMBean.java:448)
        at
com.sun.jmx.mbeanserver.DynamicMetaDataImpl.invoke(DynamicMetaDataImpl.java:213)
        at com.sun.jmx.mbeanserver.MetaDataImpl.invoke(MetaDataImpl.java:220)
        at
com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:815)
        at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:784)
        at sun.reflect.GeneratedMethodAccessor20.invoke(Unknown Source)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at
com.sun.enterprise.admin.util.proxy.ProxyClass.invoke(ProxyClass.java:77)
        at $Proxy1.invoke(Unknown Source)
        at
com.sun.enterprise.admin.server.core.jmx.SunoneInterceptor.invoke(SunoneInterceptor.java:297)
        at
com.sun.enterprise.deployment.client.DeploymentClientUtils.startApplication(DeploymentClientUtils.java:133)
        at
com.sun.enterprise.deployment.client.DeployAction.run(DeployAction.java:517)
        at java.lang.Thread.run(Thread.java:595)
Caused by: java.sql.SQLException: Error in allocating a connection. Cause:
Connection could not be allocated because:
java.security.PrivilegedActionException : Error opening socket to server
localhost on port 1527 with message : null
        at com.sun.gjc.spi.DataSource.getConnection(DataSource.java:100)
        at
oracle.toplink.essentials.jndi.JNDIConnector.connect(JNDIConnector.java:130)
        ... 51 more
[/code]

It seems that TopLink is being picked up as the JPA provider instead of
Hibernate. This seems understandable, since it's defined in our
applicationContext.xml file instead of the persistence.xml file.

persistence.xml:
[code]
<?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_1_0.xsd"
        version="1.0">

        <persistence-unit name="corePersistenceUnit"
                transaction-type="RESOURCE_LOCAL">
                <class>com.auchan.core.model.goods.Assortment</class>
        </persistence-unit>

</persistence>
[/code]

applicationContext.xml:
[code]
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:ehcache="http://www.springmodules.org/schema/ehcache"
        xmlns:jee="http://www.springframework.org/schema/jee"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="
                http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
                http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springmodules.org/schema/ehcache
http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd
                http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee.xsd
                http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">

        <jee:jndi-lookup id="mainDataSource"
                jndi-name="java:comp/env/jdbc/MainDataSource"
                proxy-interface="javax.sql.DataSource" lookup-on-startup="false" />

        <bean id="entityManagerFactory"
        
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
                <property name="dataSource" ref="mainDataSource" />
                <property name="jpaVendorAdapter">
                        <bean
                                class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                                <property name="databasePlatform"
                                        value="org.hibernate.dialect.Oracle9Dialect" />
                                <property name="showSql" value="true" />
                        </bean>
                </property>
        </bean>

        <bean id="transactionManager"
                class="org.springframework.orm.jpa.JpaTransactionManager">
                <property name="entityManagerFactory"
                        ref="entityManagerFactory" />
                <property name="dataSource" ref="mainDataSource" />
        </bean>

        <tx:annotation-driven />
</beans>
[/code]

Note that when deploying on Tomcat, we have no such error and everything is
running smoothly.

Does anybody have a clue?

Cheers,
GB

-- 
View this message in context: http://www.nabble.com/Error-with-Spring%2C-Hibernate-JPA-and-GlassFish-tf2380737.html#a6634794
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.