Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inheritance in Persistence

 
Robert Drescher
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm trying to work out a pluggable ORM for Persistence on Jboss.

I created two POJOs, one called "Post" and one called "Message".
Post defines general Attributes for each post, such as the Id, the creator, the time it was created on and a title.
Message extends Post with attributes text and replyTo (Post).

Now I want my logic ejb to return all posts (a list of the generic post from which i can extract the various subtypes) or all posts of a specific type - this way I can write a plugin which defines a new kind of "Post" without making changes in the logic.

How do I need to define the Annotations so that the tables for each kind are created when a plugin is installed and a query of all "posts" returns not only the table "Post" but also all the other inheriting tables?

Thanks for your help

Robert
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you aware of the Hibenate inheritance annotation.? You use the @Inheritance annotation after the @Entity tag on your top level class which in your case, would be the Post class. There are actually three strategies for mapping inheritance. My suggestion wouild be to take a lok at the API, to see which one suits your application needs.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To expand on Bosun's comment, here's a little tutorial I have on mapping inheritance. You might find it helpful:

Mapping Inheritance with Hibernate

-Cameron McKenzie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic