Hi,
I'm having a problem run the unit tests for a hibernate and spring-based
application with the surefire plugin.
I'm using the xdoclet plugin to generate the hibernate mapping files,
and a spring LocalSessionFactoryBean to load
the mappings, like so:
The surefire plugin:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.0</version> <!-- tried version 2.1.2 as well, to no
avail -->
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<forkMode>once</forkMode>
<includes>
<include>**/*TestSuite.java</include>
</includes>
<reportFormat>xml</reportFormat>
</configuration>
</plugin>
The xdoclet plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xdoclet-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>xdoclet</goal>
</goals>
<configuration>
<tasks>
<hibernatedoclet
excludedtags="@version,@author,@see,@todo"
destDir="${project.build.outputDirectory}">
<fileset dir="${basedir}/src/main/java">
<include name="**/model/*.java"></include>
</fileset>
<hibernate destinationFile="{0}.hbm.xml" version="3.0"
prefixWithPackageStructure="true"></hibernate>
</hibernatedoclet>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
The resulting mapping files are in target/classes.
The spring.xml looks like this:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
${hibernate.dialect}
</prop>
<prop key="hibernate.connection.autocommit">
${hibernate.connection.autocommit}
</prop>
<prop key="hibernate.hbm2ddl.auto">
${hibernate.hbm2ddl.auto}
</prop>
<prop key="hibernate.show_sql">
${hibernate.show_sql}
</prop>
</props>
</property>
<property name="mappingDirectoryLocations">
<list>
<value>classpath:</value>
</list>
</property>
</bean>
So the LocalSessionFactoryBean searches the classpath for hbm.xml files.
Now my unit tests create a ClassPathXmlApplicationContext in the setUp()
method, using the above spring.xml file.
But when the unit tests try to access one of the persistent beans, I get
the error "org.hibernate.MappingException: Unknown entity", which means
the hibernate mapping files could not be found in the classpath.
Looking at the classpath for the maven surefire plugin, I noticed that
both the target/classes and target/testClasses directories are in it
twice, which is strange but I doubt that this could be the cause...
After copying the generated hbm.xml files to src/test/resources, the
tests did not throw that Exception anymore.
I have also tried running the tests from an ant buildfile, and that
works as well.
Does anyone have an idea what could be going wrong here?
Kind regards,
Jurgen
--
Among flowers, the cherry blossom.
Among men, me.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]