• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Inheritance / Association in Hibernate

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Surfs up space ponies, I'm making gravy without this lumpy, tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic