Ok the problem of the HsqlServer approach was that it was far too heavy for testing purposes so, as I knew there is a in-memory configuration for HSQKDB I managed to get a working database access for my tests with the following dataSource bean configuration :
<beans> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName"> <value>org.hsqldb.jdbcDriver</value> </property> <property name="url"> <value>jdbc:hsqldb:mem:testdb</value> </property> <property name="username"> <value>sa</value> </property> <property name="password"> <value/> </property> <property name="defaultAutoCommit"> <value>false</value> </property> </bean> </beans> This configuration has the enormous advantage it creates no file at all and with the following hibernate.properties file in my test classpath, it doesn't even require me to create the database schema as it is created dynamically from mapping files : hibernate.hbm2ddl.auto=update This works for the first simple database access but the problem is that I get a lazy loading exception when I access the first Collection. public void testHandleInitialize() { Schaman schaman = serviceLocator.getSchaman(); schaman.initialize("test","http://test.com","[EMAIL PROTECTED]","admin","password"); assertNotNull(schaman.getRepository()); assertEquals(schaman.getRepository().getUsers().size(),1); assertEquals(schaman.getRepository().getRoles().size(),1); assertEquals(schaman.getRepository().getPrivileges().size(),1); assertEquals(schaman.getRepository().getModules().size(),0); assertEquals(schaman.getRepository().getName(),"test"); assertEquals(schaman.getRepository().getUri(),"http://test.com"); User admin = (User)schaman.getAllUsers().get(0); assertEquals(admin.getName(),"admin"); assertEquals(admin.getEmail(),"[EMAIL PROTECTED]"); assertEquals(admin.getPassword(),"password"); } This test fails on the 3rd line of the method, when I try to access the users of the repository, with the following exception Testcase: testHandleInitialize(ca.polymtl.larim.schaman.business.SchamanImplTest): Caused an ERROR Failed to lazily initialize a collection - no session or session was closed net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection - no session or session was closed at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:209) at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71) at net.sf.hibernate.collection.Set.size(Set.java:106) at ca.polymtl.larim.schaman.business.SchamanImplTest.testHandleInitialize(SchamanImplTest.java:33) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at org.apache.commons.jelly.tags.ant.AntTag.doTag(AntTag.java:185) at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:279) at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:135) at org.apache.commons.jelly.TagSupport.invokeBody(TagSupport.java:233) at org.apache.commons.jelly.tags.core.IfTag.doTag(IfTag.java:88) at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:279) at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:135) at org.apache.maven.jelly.tags.werkz.MavenGoalTag.runBodyTag(MavenGoalTag.java:79) at org.apache.maven.jelly.tags.werkz.MavenGoalTag$MavenGoalAction.performAction(MavenGoalTag.java:110) at com.werken.werkz.Goal.fire(Goal.java:639) at com.werken.werkz.Goal.attain(Goal.java:575) at com.werken.werkz.Goal.attainPrecursors(Goal.java:488) at com.werken.werkz.Goal.attain(Goal.java:573) at com.werken.werkz.Goal.attainPrecursors(Goal.java:488) at com.werken.werkz.Goal.attain(Goal.java:573) at com.werken.werkz.WerkzProject.attainGoal(WerkzProject.java:193) at org.apache.maven.jelly.tags.werkz.MavenAttainGoalTag.doTag(MavenAttainGoalTag.java:127) at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:279) at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:135) at org.apache.maven.jelly.tags.werkz.MavenGoalTag.runBodyTag(MavenGoalTag.java:79) at org.apache.maven.jelly.tags.werkz.MavenGoalTag$MavenGoalAction.performAction(MavenGoalTag.java:110) at com.werken.werkz.Goal.fire(Goal.java:639) at com.werken.werkz.Goal.attain(Goal.java:575) at org.apache.maven.plugin.PluginManager.attainGoals(PluginManager.java:671) at org.apache.maven.MavenSession.attainGoals(MavenSession.java:263) at org.apache.maven.cli.App.doMain(App.java:488) at org.apache.maven.cli.App.main(App.java:1239) 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.werken.forehead.Forehead.run(Forehead.java:551) at com.werken.forehead.Forehead.main(Forehead.java:581) Any idea of where it comes from and how I can do to keep my session opened? Thx in advance. -- S�bastien Arbogast _________________________________________________________ Reply to the post : http://galaxy.andromda.org/forum/viewtopic.php?p=250#250 Posting to http://forum.andromda.org/ is preferred over posting to the mailing list! ------------------------------------------------------- This SF.Net email is sponsored by Oracle Space Sweepstakes Want to be the first software developer in space? Enter now for the Oracle Space Sweepstakes! http://ads.osdn.com/?ad_id=7412&alloc_id=16344&op=click _______________________________________________ Andromda-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/andromda-user
