Hibernate version:
3.1
Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.Game.Main.Unit" table="UNIT">
<id name="id" column="UNIT_ID">
<generator class="native">
</generator>
</id>
<property name="unitType"/>
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.url">jdbc:mysql:///DB</property>
<property name="hibernate.connection.password">dbtest</property>
<property name="hibernate.connection.username">Hibernate</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<!-- <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property> -->
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<mapping resource="com/Game/Main/Unit.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Full stack trace of any exception that occurs:Code:
03:56:55,375 INFO Environment:479 - Hibernate 3.1
03:56:55,390 INFO Environment:509 - hibernate.properties not found
03:56:55,390 INFO Environment:525 - using CGLIB reflection optimizer
03:56:55,390 INFO Environment:555 - using JDK 1.4 java.sql.Timestamp handling
03:56:55,500 INFO Configuration:1286 - configuring from resource: /hibernate.cfg.xml
03:56:55,500 INFO Configuration:1263 - Configuration resource: /hibernate.cfg.xml
03:56:55,656 INFO Configuration:468 - Reading mappings from resource: com/Game/Main/Unit.hbm.xml
03:56:55,828 INFO HbmBinder:265 - Mapping class: com.Game.Main.Unit -> UNIT
EXCEPTION
Initial SessionFactory creation failed. org.hibernate.MappingException: Could not read mappings from resource: com/Game/Main/Unit.hbm.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.Game.Hibernate.HibernateUtil.<clinit>(HibernateUtil.java:19)
at com.Game.Main.gameTester.createAndStoreUnit(gameTester.java:275)
at com.Game.Main.gameTester.main(gameTester.java:38)
Caused by: org.hibernate.MappingException: Could not read mappings from resource: com/Game/Main/Unit.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:484)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1443)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1411)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1392)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1368)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1288)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1274)
at com.Game.Hibernate.HibernateUtil.<clinit>(HibernateUtil.java:13)
... 2 more
Caused by: org.hibernate.PropertyNotFoundException: field not found: id
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:97)
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:104)
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:104)
at org.hibernate.property.DirectPropertyAccessor.getGetter(DirectPropertyAccessor.java:112)
at org.hibernate.util.ReflectHelper.getter(ReflectHelper.java:89)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:77)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:276)
at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:366)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:299)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:238)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:109)
at org.hibernate.cfg.Configuration.add(Configuration.java:385)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:426)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:481)
... 9 more
Name and version of the database you are using:
MySql5
So, I am not sure why it can't read the file. It doesn't give me enough information to tell me what is wrong with it. When I checked the /bin directory it managed to copy everything over from the /src directory that should be there. It just can't read the Unit.hbm.xml file for whatever reason. Maybe it can't find it (Doesn't say it can't), maybe there is a parse error there.
At first I thought it was a path problem with the file, so I have tried removing com.Game.Main. from the com.Game.Main.Unit in Unit.hbm.xml and I still get the same thing. I have copied and pasted the package name from Main.Unit into the Unit.hbml.xml file to make sure that I am using the correct package name and it still isn't reading it!
The mapping resource in the hibernate config file is...correct from the looks of it. I go in the bin directory and look there and there is the Unit.hbm.xml file in the path that was specified.
Anyways, I'm stumped.
Thanks for any help.