I know this should be a pretty elementary issue to fix, but 1) I'm relatively new to Hibernate, and 2) the fixes I've found don't (seem to) apply here.
Here is the exception I am getting:
org.hibernate.MappingException: An association from the table POSTS refers to an unmapped class: com.beans.User at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1285)
This occurs when Hibernate attempts to configure itself.
The objects I'm working with are Users, Posts (abstract superclass), Statuses and Comments (concrete subclasses of Post). Each is bean from one of two tables: USERS and POSTS. The User objects are pretty vanilla: lots of bland fields describing the user. In addition to similarly boring fields, a Status and a Comment both have owners (User that posted it). What differentiates a Status from a Comment is that a Status can have a list of Comments attached to it but no parent, while a Comment has no children posts, but has a parent (yes, this is basically Facebook).
From what I've read, the problem seems to be in the many-to-one mappings, but I can't seem to find anything wrong. Here are the three configuration files I'm using.
hibernate.cfg.xml:
<hibernate-configuration> <session-factory> ... <!-- mapped persistence classes --> <mapping resource="User.hbm.xml" /> <mapping resource="Post.hbm.xml" /> </session-factory> </hibernate-configuration>
User.hbm.xml:
<hibernate-mapping> <class name="com.beans.User" entity-name="User" table="USERS" proxy="User"> <id name="uid" type="java.lang.Integer"> <column name="uid" /> <generator class="assigned" /> </id> ... </class> </hibernate-mapping>
Post.hbm.xml:
<hibernate-mapping>
<class name="com.beans.Post" entity-name="Post" table="POSTS" proxy="Post" abstract="true">
<id name="pid" type="java.lang.Integer">
<column name="pid" />
<generator class="assigned" />
</id>
<discriminator column="type" />
<one-to-one name="parent" class="com.beans.Post"></one-to-one>
<many-to-one name="owner" class="com.beans.User" update="false" fetch="select">
<column name="owner" />
</many-to-one>
<property name="postDate" type="java.sql.Timestamp" update="false">
<column name="post_date" />
</property>
<property name="content" type="java.lang.String" update="false">
<column name="content" />
</property>
<property name="type" type="string" update="false">
<column name="type" />
</property>
<subclass name="com.beans.Status" discriminator-value="status">
<list name="children" inverse="false" table="POSTS" lazy="true">
<key column="pid" />
<index />
<one-to-many class="com.beans.Comment" />
</list>
</subclass>
<subclass name="com.beans.Comment" discriminator-value="comment"></subclass>
</class>
</hibernate-mapping>
I get the feeling I need to specify somewhere the fact that a Status contains an ArrayList of Comment's, but isn't that done implicitly through the "list" construct in the Post.hbm.xml file?
The xml files exist in my classpath (WEB-INF/classes), and the .java files themselves are visible to the application as well. Insights would be appreciated!