aspose file tools*
The moose likes Object Relational Mapping and the fly likes Inheritance / Association in Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Inheritance / Association in Hibernate" Watch "Inheritance / Association in Hibernate" New topic
Author

Inheritance / Association in Hibernate

Vivek Thirumalai
Greenhorn

Joined: Oct 08, 2007
Posts: 3
Hi,

I am trying to use inheritance/association in hibernate. This is my scenario :

1) Author class that has a set of objects of type Book(abstract class)
2) FictionBook and RomanceBook extend Book and I am using table/concrete class strategy

These are my mapping files :

Author.hbm.xml :
<hibernate-mapping>

<class name="Author" table="authors1">
<id name="id" column="au_id">
<generator class="native"/>
</id>
<property name="name" column="Name"/>
<set name="books" cascade="all" lazy="false" >
<key column="authorId" not-null="true"/>
<one-to-many class="Book"/>
</set>
<!-- This mapping maps the Author class to the table authors in pubs3 -->
</class>
</hibernate-mapping>


Book.hbm.xml :

<hibernate-mapping>
<class name="FictionBook" table="fictionbook" >
<id name="id">
<generator class="native"/>
</id>
<property name="name" />
</class>

<class name="RomanceBook" table="romancebook">
<id name="id">
<generator class="native"/>
</id>
<property name="name" />
<property name="genre"/>
</class>
</hibernate-mapping>


But I am getting the following exception :
Association references unmapped class: Book

It is working if I am using either inheritance or association separately ( Author having a set of Book(no inheritance) or just inheritance without any exception). I think the problem might be, Book is being referenced in Author.hbm.xml but there is no mapping for it Book.hbm.xml.

Could someone help me out on this?

Thanks,
Vivek.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Inheritance / Association in Hibernate