Hibernate version: 3.0.5
Mapping documents:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!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.manytomany.Preferences"
table="test_preferences"
>
<id
name="id"
column="id"
type="java.lang.Long"
>
<generator class="native">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Preferences.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<component
name="warningPreferences"
class="com.manytomany.WarningPreferences"
>
<property
name="enabled"
type="java.lang.Boolean"
update="true"
insert="true"
column="warningprefs_enabled"
/>
<set
name="warnedUsers"
table="test_warned_users"
lazy="true"
inverse="true"
cascade="save-update"
sort="unsorted"
>
<key
column="warningpreferences_id"
>
</key>
<many-to-many
class="com.manytomany.TestUser"
column="user_id"
outer-join="auto"
/>
</set>
</component>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Preferences.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!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.manytomany.TestUser"
table="test_user"
>
<id
name="id"
column="id"
type="java.lang.Long"
>
<generator class="native">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-TestUser.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<property
name="name"
type="java.lang.String"
update="true"
insert="true"
column="name"
unique="true"
/>
<set
name="warningPreferences"
table="test_warned_users"
lazy="true"
inverse="false"
cascade="save-update"
sort="unsorted"
>
<key
column="user_id"
>
</key>
<many-to-many
class="com.manytomany.WarningPreferences"
column="warningpreferences_id"
outer-join="auto"
/>
</set>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-TestUser.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Full stack trace of any exception that occurs:Code:
org.hibernate.MappingException: An association from the table test_warned_users refers to an unmapped class: com.manytomany.WarningPreferences
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:968)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:921)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:999)
[snip]
Caused by: org.hibernate.MappingException: An association from the table test_warned_users refers to an unmapped class: com.manytomany.WarningPreferences
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:968)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:921)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:999)
at com.ims.wintox.model.persistence.HibernateUtil.init(HibernateUtil.java:120)
... 2 more
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:968)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:921)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:999)
... 3 more
Name and version of the database you are using: PostgreSQL 8.1
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Referencing the following figure, I'm trying to associate a hibernate component with another table in a many-to-many relationship. I get an error about WarningPreferences being unmapped when attemping to build my database. What's wrong?
http://www.dafunks.com/hibernate/ManyTo ... ponent.jpg
According to this link (
http://www.hibernate.org/hib_docs/refer ... nents.html), this should be possible:
The properties of a component may be of any Hibernate type (collections, many-to-one associations, other components, etc). Nested components should not be considered an exotic usage. Hibernate is intended to support a very fine-grained object model.