Hi all,
I don't know if this is a problem as a result of something I did incorrectly or if this is an actual problem with the Hibernate Code Generation (Exporter : .hbm.xml) because I am relatively new to using Hibernate.
The problem appears to be that the hbm.xml file generated for two classes that have a Many-To-Many relationship does not include the attribute for the link (aka association) table name.
Hibernate version:3.2.0.cr4
Full stack trace of any exception that occurs:
WARNING: SQL Error: 1146, SQLState: 42S02
5/09/2006 14:00:24 org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Table 'blah.enginemodels' doesn't exist
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not initialize a collection: [com.acme.model.ChassisModel.engineModels#1]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
Name and version of the database you are using:MySQL 5.0
When I tried to navigate across the association while using the generated hbm.xml file I got the above stack trace.
Code:
<set name="engineModels" inverse="true">
<key>
<column name="chassis_model_pkid" not-null="true">
<comment></comment>
</column>
</key>
<many-to-many entity-name="nz.co.krazykarts.model.EngineModel">
<column name="engine_model_pkid" not-null="true">
<comment></comment>
</column>
</many-to-many>
</set>
When I added the table="lt_engine_model_chassis_model" attribute to the "set" element the navigation succeeded.
Code:
<set name="engineModels" inverse="true" table="lt_engine_model_chassis_model">
<key>
<column name="chassis_model_pkid" not-null="true">
<comment></comment>
</column>
</key>
<many-to-many entity-name="nz.co.krazykarts.model.EngineModel">
<column name="engine_model_pkid" not-null="true">
<comment></comment>
</column>
</many-to-many>
</set>