persistence@glassfish.java.net

Re: Error with Spring, Hibernate JPA and GlassFish

From: Guillaume Bilodeau <gbilodeau_at_yahoo.com>
Date: Wed, 4 Oct 2006 02:43:30 -0700 (PDT)

Ok, thanks for looking into this. I've filed issue 1251, let me know if you
need more information.

Thanks again,
GB


Sanjeeb Kumar Sahoo wrote:
>
> I just looked at the code and found that GF will load all the
> persistence units that it can discover in an application irrespective of
> an application using those persistence unit in Java EE style or not. In
> your case, even though you are not using it in Java EE style, it is
> loading it. Can you file an *enhancement* request in GF issue tracker
> (category entity-persistence) indicating that GF should not load a
> persistence unit unless an application requires it. GF should be able to
> understand an application's dependency on a persistence unit by looking
> at various annotations and XML DD entries.
>
> Thanks,
> Sahoo
> Guillaume Bilodeau wrote:
>> Actually no, the only annotation I'm using is @Entity on the class I'm
>> referring to in persistence.xml. Should GlassFish try to load the JPA
>> provider even though I'm not using the @PersistenceContext or
>> @PersistenceUnit?
>>
>> It would be great if this behavior could be somehow disabled, or at least
>> deferred. As you rightly point out, defining my persistence unit in
>> Spring
>> is better for us since it allows us to deploy locally to Tomcat for our
>> development process.
>>
>> Thanks,
>> GB
>>
>>
>> Sanjeeb Kumar Sahoo wrote:
>>
>>> From the stack trace it looks like you are injecting either an emf or
>>> an em using @PersistenceContext or @PersistenceUnit or its equivalent
>>> XML DD. Is this true? So GlassFish is trying to resolve the injected em
>>> or emf when your web app is loaded. GlassFish uses information from
>>> persistence.xml only to decide the provider to be used. It does not read
>>> your Spring configuration file. You did not see this problem in Tomcat
>>> because Tomcat does not yet understand @PersistenceContext or
>>> @PersistenceUnit as Marina hinted in her email.
>>>
>>> Your concern for duplicating the info in persistence.xml and in Spring
>>> XML is very valid. You should either use Spring to set the bean property
>>> or let GF inject it. If you opt for the former, then remove any
>>> injection annotations from your code. If you choose the later, then
>>> remove the JPA configurations from Spring xml file. With later approach,
>>> your app will correctly in GF, but no more in Tomcat.
>>>
>>> Thanks,
>>> Sahoo
>>>
>>> Guillaume Bilodeau wrote:
>>>
>>>> Hi Marina,
>>>>
>>>> Yes that's exactly what I thought. But what if I don't want GlassFish
>>>> to
>>>> pick up anything, since I'm defining it in my Spring application
>>>> context
>>>> and
>>>> it will be loaded when this context will itself be loaded?
>>>>
>>>> I know I can define Hibernate as the JPA provider in my persistence.xml
>>>> (as
>>>> suggested by Sahoo) but I don't know how this will interact with my
>>>> Spring
>>>> definition.
>>>>
>>>> I'll try that and get back to you.
>>>>
>>>> Thanks for your answer,
>>>> GB
>>>>
>>>>
>>>> Marina Vatkina wrote:
>>>>
>>>>
>>>>> Hi,
>>>>>
>>>>> Of course we pick up TopLink - it's the default provider, and you
>>>>> didn't
>>>>> tell us otherwise. Tomcat is not a Java EE 5 container, and is not
>>>>> required
>>>>> to do so.
>>>>>
>>>>> regards,
>>>>> -marina
>>>>>
>>>>> Guillaume Bilodeau wrote:
>>>>>
>>>>>
>>>>>> 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>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#a6636636
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.