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