Many similar problems have been posted on this site, but no solutions have worked for me yet, any help with this is greatly appreciated!
Using:
Hibernate 2.1.7, Eclipse, Tomcat 5.0, MySql DB
XDoclet for code generation, both for the *.hbm.xml and hibernate.cfg.xml
Trying to run a simple testcase on a very simple test application using JUnit within Eclipse. One table, one object to map:
Get the following Errors from console:
net.sf.hibernate.MappingException Error reading resource /com/chasparsons/obj/UserDataObject.hbm.xml
Mapping File:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="com.chasparsons.obj.UserDataObject"
table="user"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="id"
type="java.lang.Long"
>
<generator class="native">
</generator>
</id>
<property
name="firstName"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="firstname"
/>
<property
name="lastName"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="lastname"
/>
<property
name="email"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="email"
/>
<property
name="password"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="password"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-UserDataObject.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<!-- Generated file - Do not edit! -->
<hibernate-configuration>
<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory>
<!-- properties -->
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">false</property>
<property name="use_outer_join">false</property>
<property name="connection.username">javauser</property>
<property name="connection.password">javapassword</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/hibernate</property>
<!-- mapping files -->
<mapping resource="com/chasparsons/obj/UserDataObject.hbm.xml"/>
</session-factory>
</hibernate-configuration>
[INFO] Environment - -Hibernate 2.1.7
[INFO] Environment - -hibernate.properties not found
[INFO] Environment - -using CGLIB reflection optimizer
[INFO] Environment - -using JDK 1.4 java.sql.Timestamp handling
[INFO] Configuration - -configuring from resource: /hibernate.cfg.xml
[INFO] Configuration - -Configuration resource: /hibernate.cfg.xml
[DEBUG] DTDEntityResolver - -trying to locate
http://hibernate.sourceforge.net/hibern ... on-2.0.dtd in classpath under net/sf/hibernate/
[DEBUG] DTDEntityResolver - -found
http://hibernate.sourceforge.net/hibern ... on-2.0.dtd in classpath
[DEBUG] Configuration - -dialect=net.sf.hibernate.dialect.MySQLDialect
[DEBUG] Configuration - -show_sql=false
[DEBUG] Configuration - -use_outer_join=false
[DEBUG] Configuration - -connection.username=javauser
[DEBUG] Configuration - -connection.password=javapassword
[DEBUG] Configuration - -connection.driver_class=com.mysql.jdbc.Driver
[DEBUG] Configuration - -connection.url=jdbc:mysql://localhost/hibernate
[DEBUG] Configuration - -null<-org.dom4j.tree.DefaultAttribute@7808b9 [Attribute: name resource value "com/chasparsons/obj/UserDataObject.hbm.xml"]
[INFO] Configuration - -Mapping resource: com/chasparsons/obj/UserDataObject.hbm.xml
[DEBUG] DTDEntityResolver - -trying to locate
http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
[DEBUG] DTDEntityResolver - -found
http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
[INFO] Binder - -Mapping class: com.chasparsons.obj.UserDataObject -> user
[DEBUG] Binder - -Mapped property: id -> id, type: long
[DEBUG] Binder - -Mapped property: firstName -> firstname, type: string
[DEBUG] Binder - -Mapped property: lastName -> lastname, type: string
[DEBUG] Binder - -Mapped property: email -> email, type: string
[DEBUG] Binder - -Mapped property: password -> password, type: string
[INFO] Configuration - -Configured SessionFactory: null
[DEBUG] Configuration - -properties: {hibernate.connection.password=javapassword, java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, sun.boot.library.path=C:\j2sdk1.4.2_05\jre\bin, java.vm.version=1.4.2_05-b04, hibernate.connection.username=javauser, java.vm.vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separator=;, java.vm.name=Java HotSpot(TM) Client VM, file.encoding.pkg=sun.io, use_outer_join=false, user.country=US, sun.os.patch.level=Service Pack 2, java.vm.specification.name=Java Virtual Machine Specification, user.dir=C:\eclipse\workspace\Chas, java.runtime.version=1.4.2_05-b04, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=C:\j2sdk1.4.2_05\jre\lib\endorsed, os.arch=x86, java.io.tmpdir=C:\DOCUME~1\CHASPA~1\LOCALS~1\Temp\, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., user.variant=, os.name=Windows XP, org.apache.commons.logging.simplelog.defaultlog=debug, sun.java2d.fontpath=, java.library.path=C:\j2sdk1.4.2_05\bin;.;C:\WINDOWS\system32;C:\WINDOWS;c:\program files\imagemagick-6.1.3-q16;C:\Perl\bin\;C:\PROGRAM FILES\THINKPAD\UTILITIES;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\ATI Technologies\ATI Control Panel;C:\Program Files\PC-Doctor for Windows\services;C:\Program Files\Common Files\MDL Shared\ISIS;C:\php;C:\java\Maven 1.0\bin;C:\java\apache-ant-1.6.2\bin, java.specification.name=Java Platform API Specification, java.class.version=48.0, java.util.prefs.PreferencesFactory=java.util.prefs.WindowsPreferencesFactory, os.version=5.1, connection.password=javapassword, user.home=C:\Documents and Settings\chasparsons, user.timezone=, connection.username=javauser, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=Cp1252, java.specification.version=1.4, hibernate.connection.driver_class=com.mysql.jdbc.Driver, show_sql=false, user.name=chasparsons, java.class.path=/c:/eclipse/plugins/org.eclipse.jdt.junit_3.0.0/junitsupport.jar;/c:/eclipse/plugins/org.eclipse.jdt.junit.runtime_3.0.0/junitruntime.jar;C:\eclipse\workspace\Chas\work;C:\eclipse\workspace\Chas\WEB-INF\classes;C:\eclipse\workspace\Chas\WEB-INF\lib\commons-beanutils.jar;C:\eclipse\workspace\Chas\WEB-INF\lib\commons-collections.jar;C:\eclipse\workspace\Chas\WEB-INF\lib\commons-digester.jar;C:\eclipse\workspace\Chas\WEB-INF\lib\commons-fileupload.jar;C:\eclipse\workspace\Chas\WEB-INF\lib\commons-lang.jar;C:\eclipse\workspace\Chas\WEB-INF\lib\commons-logging.jar;C:\eclipse\workspace\Chas\WEB-INF\lib\commons-validator.jar;C:\eclipse\workspace\Chas\WEB-INF\lib\jakarta-oro.jar;C:\eclipse\workspace\Chas\WEB-INF\lib\struts.jar;C:\eclipse\workspace\Chas\WEB-INF\lib\struts-legacy.jar;C:\java\jakarta-tomcat-5.0.28\common\lib\servlet-api.jar;C:\java\jakarta-tomcat-5.0.28\common\lib\jasper-runtime.jar;C:\java\jakarta-tomcat-5.0.28\common\lib\jsp-api.jar;C:\eclipse\workspace\Chas\WEB-INF\lib\cglib-full-2.0.2.jar;C:\eclipse\workspace\Chas\WEB-INF\lib\dom4j-1.4.jar;C:\eclipse\workspace\Chas\WEB-INF\lib\ehcache-0.9.jar;C:\eclipse\workspace\Chas\WEB-INF\lib\hibernate2.jar;C:\eclipse\workspace\Chas\WEB-INF\lib\log4j-1.2.8.jar;C:\eclipse\workspace\Chas\WEB-INF\lib\odmg-3.0.jar;C:\eclipse\workspace\Chas\WEB-INF\lib\jta.jar;C:\eclipse\plugins\org.junit_3.8.1\junit.jar, hibernate.show_sql=false, java.vm.specification.version=1.0, java.home=C:\j2sdk1.4.2_05\jre, sun.arch.data.model=32, hibernate.connection.url=jdbc:mysql://localhost/hibernate, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, user.language=en, java.specification.vendor=Sun Microsystems Inc., awt.toolkit=sun.awt.windows.WToolkit, hibernate.cglib.use_reflection_optimizer=true, java.vm.info=mixed mode, java.version=1.4.2_05, java.ext.dirs=C:\j2sdk1.4.2_05\jre\lib\ext, sun.boot.class.path=C:\j2sdk1.4.2_05\jre\lib\rt.jar;C:\j2sdk1.4.2_05\jre\lib\sunrsasign.jar;C:\j2sdk1.4.2_05\jre\lib\jsse.jar;C:\j2sdk1.4.2_05\jre\lib\jce.jar;C:\j2sdk1.4.2_05\jre\lib\charsets.jar;C:\j2sdk1.4.2_05\jre\lib\ext\dnsns.jar;C:\j2sdk1.4.2_05\jre\lib\ext\ldapsec.jar;C:\j2sdk1.4.2_05\jre\lib\ext\localedata.jar;C:\j2sdk1.4.2_05\jre\lib\ext\mysql-connector-java-3.0.14-production-bin.jar;C:\j2sdk1.4.2_05\jre\lib\ext\sunjce_provider.jar, java.vendor=Sun Microsystems Inc., connection.driver_class=com.mysql.jdbc.Driver, file.separator=\, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, hibernate.use_outer_join=false, connection.url=jdbc:mysql://localhost/hibernate, dialect=net.sf.hibernate.dialect.MySQLDialect, org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog, sun.cpu.isalist=pentium i486 i386}
[INFO] Configuration - -Mapping resource: com/chasparsons/obj/UserDataObject.hbm.xml
[DEBUG] DTDEntityResolver - -trying to locate
http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
[DEBUG] DTDEntityResolver - -found
http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
[ERROR] Configuration - -Could not compile the mapping document <net.sf.hibernate.MappingException: duplicate import: UserDataObject>net.sf.hibernate.MappingException: duplicate import: UserDataObject
at net.sf.hibernate.cfg.Mappings.addImport(Mappings.java:85)
at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:127)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:222)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1257)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:252)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:288)
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:354)
at com.chasparsons.hibernate.ConnectionFactory.<init>(ConnectionFactory.java:59)
at com.chasparsons.hibernate.ConnectionFactory.getInstance(ConnectionFactory.java:107)
at com.chasparsons.hibernate.UserDAOTest.setUp(UserDAOTest.java:33)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)