Results 1 to 8 of 8

Thread: Problem in Spring 1.2.3 and TopLink 10.1.3

  1. #1
    Join Date
    Aug 2005
    Posts
    2

    Default Problem in Spring 1.2.3 and TopLink 10.1.3

    I defined the following bean in ApplicationContext.xml.

    <bean id="mySessionFactory" class="org.springframework.orm.toplink.LocalSessio nFactoryBean">
    <property name="configLocation" value="/WEB-INF/toplink-sessions.xml"/>
    <property name="dataSource" ref="dataSource"/>
    </bean>

    When I load my application, I can confirm mySessionFactory is created as a singleton. But in my application, when it tried to load DAO bean having this sessionFactory with XmlBeanFactory, it throws Validation Exception saying "Session [Session] is already logged in".

    Even though it is a singleton, it seems like to reinstantiate the bean.

    Could you give me any solution or suggestion ?

    Thanks.

  2. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    when it tried to load DAO bean having this sessionFactory with XmlBeanFactory, it throws Validation Exception saying "Session [Session] is already logged in".
    Can you please provide the stack trace (edited if it's long!) and the code you're using to obtain the DAO?
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  3. #3
    Join Date
    Aug 2005
    Posts
    2

    Default

    This is the log when I brought up my application.

    Aug 10, 2005 9:34:58 AM org.springframework.beans.factory.support.Abstract BeanFactory getBean

    INFO: Creating shared instance of singleton bean 'mySessionFactory'

    [TopLink Info]: 2005.08.10 09:34:59.545--ServerSession(1068)--Thread(Thread[HttpRequestHandler-198,5,ApplicationServerThreadGroup])--TopLink, version: Oracle TopLink - 10g Developer Preview 3 (10.1.3.0 ) (Build 041116)

    [TopLink Config]: 2005.08.10 09:34:59.565--ServerSession(1068)--Thread(Thread[HttpRequestHandler-198,5,ApplicationServerThreadGroup])--Connection(1069)--connecting(DatabaseLogin(

    platform=>DatabasePlatform

    user name=> ""

    datasource name=>null

    ))

    [TopLink Config]: 2005.08.10 09:35:00.175--ServerSession(1068)--Thread(Thread[HttpRequestHandler-198,5,ApplicationServerThreadGroup])--Connection(1069)--Connected: jdbc:oracle:thin:@localhost:1521:myorcl

    User: SYS

    Database: Oracle Version: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production
    With the Partitioning, OLAP and Data Mining options

    Driver: Oracle JDBC driver Version: 10.1.0.3.0

    [TopLink Config]: 2005.08.10 09:35:00.175--ServerSession(1068)--Thread(Thread[HttpRequestHandler-198,5,ApplicationServerThreadGroup])--Connection(1083)--connecting(DatabaseLogin(

    platform=>DatabasePlatform

    user name=> ""

    datasource name=>null

    ))

    [TopLink Config]: 2005.08.10 09:35:00.346--ServerSession(1068)--Thread(Thread[HttpRequestHandler-198,5,ApplicationServerThreadGroup])--Connection(1083)--Connected: jdbc:oracle:thin:@localhost:1521:myorcl

    User: SYS

    Database: Oracle Version: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production
    With the Partitioning, OLAP and Data Mining options

    Driver: Oracle JDBC driver Version: 10.1.0.3.0

    [TopLink Info]: 2005.08.10 09:35:00.356--ServerSession(1068)--Thread(Thread[HttpRequestHandler-198,5,ApplicationServerThreadGroup])--Session login successful

    Aug 10, 2005 9:35:00 AM org.springframework.beans.factory.support.Abstract BeanFactory getBean

    INFO: Creating shared instance of singleton bean 'myTopLinkDao'

    Aug 10, 2005 9:35:00 AM org.springframework.web.context.ContextLoader initWebApplicationContext

    INFO: Using context class [org.springframework.web.context.support.XmlWebAppl icationContext] for root WebApplicationContext

    Aug 10, 2005 9:35:00 AM org.springframework.web.context.ContextLoader initWebApplicationContext

    INFO: Root WebApplicationContext: initialization completed in 2374 ms




    This is the code to obtain the DAO.

    ClassPathResource res = new ClassPathResource("../applicationContext.xml");
    XmlBeanFactory factory = new XmlBeanFactory(res);
    TopLinkDAO topLinkJobs = (TopLinkDAO)factory.getBean("myTopLinkDao");


    This is the stacke trace.

    05/08/10 09:36:10 org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'mySessionFactory' defined in class path resource [../applicationContext.xml]: Initialization of bean failed; nested exception is oracle.toplink.exceptions.ValidationException:

    Exception Description: Session [Session] is already logged in.

    Local Exception Stack:

    Exception [TOPLINK-7128] (Oracle TopLink - 10g Developer Preview 3 (10.1.3.0 ) (Build 041116)): oracle.toplink.exceptions.ValidationException

    Exception Description: Session [Session] is already logged in.

    at oracle.toplink.exceptions.ValidationException.alre adyLoggedIn(ValidationException.java:1119)

    at oracle.toplink.publicinterface.DatabaseSession.log in(DatabaseSession.java:493)

    at org.springframework.orm.toplink.LocalSessionFactor y.createSessionFactory(LocalSessionFactory.java:29 2)

    at oracle.security.avmt.OracleSessionFactoryBean.afte rPropertiesSet(OracleSessionFactoryBean.java:36)

    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1003)

    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:348)

    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:226)

    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:147)

    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveReference(BeanDefinitio nValueResolver.java:176)

    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveValueIfNecessary(BeanDe finitionValueResolver.java:105)

    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:957)

    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:768)

    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:330)

    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:226)

    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:147)



    Thanks.

  4. #4
    Join Date
    Aug 2004
    Location
    Linz, Austria
    Posts
    391

    Default

    Could it be that you're loading your application context definition file explicitly through an XmlBeanFactory, while still loading the root application context through Spring's ContextLoaderListener in web.xml? That would indeed cause all beans defined in that application context file to be loaded twice: once by your ContextLoaderListener, once by your explicit XmlBeanFactory setup.

    I guess what you really want to do is simply access your DAO from your root application context, as loaded by the ContextLoaderListener. You don't need to create a fresh XmlBeanFactory; you even must not do that, as you want to access your shared DAO instance in the root context. Instead, simply get a reference to your root context and fetch the shared bean from there:

    Code:
    WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext&#40;servletContext&#41;;
    TopLinkDAO myTopLinkDao = &#40;TopLinkDAO&#41; wac.getBean&#40;"myTopLinkDao&#41;;
    Juergen

  5. #5
    Join Date
    Aug 2005
    Posts
    3

    Default Re: Problem in Spring 1.2.3 and TopLink 10.1.3

    I have a similar problem too: I am trying to run a JUnit Test against a dao. When I execute only one Method everything is ok, when I execute more than one, I get the "oracle.toplink.exceptions.ValidationException
    Exception Description: Session [cdmSession] is already logged in." Exception on all method calls after the first one.

    Code:
    public class CountryDaoImplTest extends TestCase &#123;
      CountryDao countryDao;
    
    JUnit TestCase&#58;
      public void testFindByIsoCode&#40;&#41; throws Exception &#123;
        Country cntry = countryDao.findByIsoCode&#40;"CH"&#41;;
        assertNotNull&#40;cntry&#41;;
        assertEquals&#40;cntry.getIsoCode&#40;&#41;, "CH"&#41;;
      &#125;
    
      public void testGet&#40;&#41; throws Exception &#123;
        Country cntry = countryDao.get&#40;1000&#41;;
        assertNotNull&#40;cntry&#41;;
      &#125;
    
      public void testListByIsoCode&#40;&#41; throws Exception &#123;
        List<Country> allCountries = countryDao.list&#40;Country.OrderBy.ISO_CODE&#41;;
        assertNotNull&#40;allCountries&#41;;
        assertTrue&#40;allCountries.size&#40;&#41; > 0&#41;;
        String isoCode = "";
        for &#40;int i = 0, size = allCountries.size&#40;&#41;; i < size; i++&#41; &#123;
          if &#40;i > 0&#41; &#123;
            assertTrue&#40;allCountries.get&#40;i&#41;.getIsoCode&#40;&#41;.compareTo&#40;allCountries.get&#40;i - 1&#41;.getIsoCode&#40;&#41;&#41; > 0&#41;;
          &#125;
        &#125;
      &#125;
    
    Spring config&#58;
      <bean id="topLinkSessionFactory" class="org.springframework.orm.toplink.LocalSessionFactoryBean">
        <property name="configLocation" value="toplink-sessions.xml"/>
        <property name="sessionName" value="cdmSession"/>
      </bean>
    
    StackTrace&#58;
    17-Aug-2005 15&#58;16&#58;02 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO&#58; Loading XML bean definitions from file &#91;D&#58;\projects\SPI-CDM\cdmapp\config\spring-appcontext.xml&#93;
    17-Aug-2005 15&#58;16&#58;02 org.springframework.context.support.AbstractRefreshableApplicationContext refreshBeanFactory
    INFO&#58; Bean factory for application context &#91;org.springframework.context.support.FileSystemXmlApplicationContext;hashCode=27742346&#93;&#58; org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans &#91;countryDao,masterdataService,topLinkSessionFactory&#93;; root of BeanFactory hierarchy
    17-Aug-2005 15&#58;16&#58;02 org.springframework.context.support.AbstractApplicationContext refresh
    INFO&#58; 3 beans defined in application context &#91;org.springframework.context.support.FileSystemXmlApplicationContext;hashCode=27742346&#93;
    17-Aug-2005 15&#58;16&#58;02 org.springframework.context.support.AbstractApplicationContext initMessageSource
    INFO&#58; Unable to locate MessageSource with name 'messageSource'&#58; using default &#91;org.springframework.context.support.DelegatingMessageSource@19b04e2&#93;
    17-Aug-2005 15&#58;16&#58;02 org.springframework.context.support.AbstractApplicationContext initApplicationEventMulticaster
    INFO&#58; Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster'&#58; using default &#91;org.springframework.context.event.SimpleApplicationEventMulticaster@5dcec6&#93;
    17-Aug-2005 15&#58;16&#58;02 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
    INFO&#58; Pre-instantiating singletons in factory &#91;org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans &#91;countryDao,masterdataService,topLinkSessionFactory&#93;; root of BeanFactory hierarchy&#93;
    17-Aug-2005 15&#58;16&#58;02 org.springframework.beans.factory.support.AbstractBeanFactory getBean
    INFO&#58; Creating shared instance of singleton bean 'countryDao'
    17-Aug-2005 15&#58;16&#58;02 org.springframework.beans.factory.support.AbstractBeanFactory getBean
    INFO&#58; Creating shared instance of singleton bean 'topLinkSessionFactory'
    17-Aug-2005 15&#58;16&#58;02 org.springframework.orm.toplink.LocalSessionFactory createSessionFactory
    INFO&#58; Initializing TopLink SessionFactory from &#91;toplink-sessions.xml&#93;
    17-Aug-2005 15&#58;16&#58;02 org.springframework.beans.factory.support.AbstractBeanFactory destroySingletons
    INFO&#58; Destroying singletons in factory &#123;org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans &#91;countryDao,masterdataService,topLinkSessionFactory&#93;; root of BeanFactory hierarchy&#125;
    
    org.springframework.beans.factory.BeanCreationException&#58; Error creating bean with name 'countryDao' defined in file &#91;D&#58;\projects\SPI-CDM\cdmapp\config\spring-appcontext.xml&#93;&#58; Can't resolve reference to bean 'topLinkSessionFactory' while setting property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException&#58; Error creating bean with name 'topLinkSessionFactory' defined in file &#91;D&#58;\projects\SPI-CDM\cdmapp\config\spring-appcontext.xml&#93;&#58; Initialization of bean failed; nested exception is oracle.toplink.exceptions.ValidationException&#58; 
    Exception Description&#58; Session &#91;cdmSession&#93; is already logged in.
    org.springframework.beans.factory.BeanCreationException&#58; Error creating bean with name 'topLinkSessionFactory' defined in file &#91;D&#58;\projects\SPI-CDM\cdmapp\config\spring-appcontext.xml&#93;&#58; Initialization of bean failed; nested exception is oracle.toplink.exceptions.ValidationException&#58; 
    Exception Description&#58; Session &#91;cdmSession&#93; is already logged in.
    Local Exception Stack&#58; 
    Exception &#91;TOPLINK-7108&#93; &#40;OracleAS TopLink - 10g &#40;9.0.4.5&#41; &#40;Build 040930&#41;&#41;&#58; oracle.toplink.exceptions.ValidationException
    Exception Description&#58; Session &#91;cdmSession&#93; is already logged in.
    	at oracle.toplink.exceptions.ValidationException.alreadyLoggedIn&#40;ValidationException.java&#58;872&#41;
    	at oracle.toplink.publicinterface.DatabaseSession.login&#40;DatabaseSession.java&#58;527&#41;
    	at org.springframework.orm.toplink.LocalSessionFactory.createSessionFactory&#40;LocalSessionFactory.java&#58;292&#41;
    	at org.springframework.orm.toplink.LocalSessionFactoryBean.afterPropertiesSet&#40;LocalSessionFactoryBean.java&#58;51&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods&#40;AbstractAutowireCapableBeanFactory.java&#58;1003&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;348&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;226&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;147&#41;
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference&#40;BeanDefinitionValueResolver.java&#58;176&#41;
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary&#40;BeanDefinitionValueResolver.java&#58;105&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues&#40;AbstractAutowireCapableBeanFactory.java&#58;957&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean&#40;AbstractAutowireCapableBeanFactory.java&#58;768&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;330&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;226&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;147&#41;
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons&#40;DefaultListableBeanFactory.java&#58;275&#41;
    	at org.springframework.context.support.AbstractApplicationContext.refresh&#40;AbstractApplicationContext.java&#58;317&#41;
    	at org.springframework.context.support.FileSystemXmlApplicationContext.<init>&#40;FileSystemXmlApplicationContext.java&#58;82&#41;
    	at org.springframework.context.support.FileSystemXmlApplicationContext.<init>&#40;FileSystemXmlApplicationContext.java&#58;67&#41;
    	at org.springframework.context.support.FileSystemXmlApplicationContext.<init>&#40;FileSystemXmlApplicationContext.java&#58;58&#41;
    	at ch.clx.spi.cdm.dao.toplink.CountryDaoImplTest.setUp&#40;CountryDaoImplTest.java&#58;27&#41;
    	at com.intellij.rt.execution.junit2.JUnitStarter.main&#40;JUnitStarter.java&#58;31&#41;
    	at sun.reflect.NativeMethodAccessorImpl.invoke0&#40;Native Method&#41;
    	at sun.reflect.NativeMethodAccessorImpl.invoke&#40;NativeMethodAccessorImpl.java&#58;39&#41;
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke&#40;DelegatingMethodAccessorImpl.java&#58;25&#41;
    	at com.intellij.rt.execution.application.AppMain.main&#40;AppMain.java&#58;86&#41;

  6. #6
    Join Date
    Aug 2004
    Location
    Linz, Austria
    Posts
    391

    Default

    This probably may arise if you load multiple application contexts in the same class loader, with each context having its TopLink SessionFactory definition. The problem here is the TopLink SessionManager singleton, which caches created Sessions by name - per class loader. This can lead to the side effect that you're experiencing.

    To address this, I've refined our LocalSessionFactory to use its own SessionManager instance instead of accessing "SessionManager.getManager()". This should suppress any caching at the class loader level, giving a completely independent TopLink Session for each Spring application context. This will be released in Spring 1.2.4.

    Juergen

  7. #7
    Join Date
    Aug 2004
    Location
    Linz, Austria
    Posts
    391

    Default

    I've just committed the change to CVS. It should be available in one of the next nightly builds (it might not be in time for this night's build, but definitely for the next).

    Juergen

  8. #8
    Join Date
    Aug 2005
    Posts
    3

    Default Problem in Spring 1.2.3 and TopLink 10.1.3

    With the spring-framework-1.2.4-with-dependencies-build.328-20050819.zip it works.

    Thanks
    Mario

Similar Threads

  1. Replies: 3
    Last Post: Oct 31st, 2005, 10:33 AM
  2. TopLink in Spring 1.2
    By Mike Plawecki in forum Data
    Replies: 0
    Last Post: May 16th, 2005, 10:30 AM
  3. Spring Framework 1.2 Released
    By Colin Sampaleanu in forum Announcements
    Replies: 0
    Last Post: May 13th, 2005, 11:20 PM
  4. TopLink - Is it really transparent?
    By tnabil in forum Data
    Replies: 1
    Last Post: Feb 16th, 2005, 06:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •