This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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

Inheritance / Association in Hibernate

Vivek Thirumalai

Joined: Oct 08, 2007
Posts: 3

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 :

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

Book.hbm.xml :

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

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

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?

Have you checked out Aspose?
subject: Inheritance / Association in Hibernate
It's not a secret anymore!