Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inheritance / Association in Hibernate

 
Vivek Thirumalai
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic