• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mapping instances of a class to multiple tables

 
Jomy George
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

I am new to ORM. I would like to know if i can map instances of a class in to multiple tables based on a property of that instance.
For example, I have a class Student with a property named type (having values 'junior', or 'senior'). Based on this property value i need to save instances to respective tables.
Both tables (junior, and senior) hold the same structure.

Could anyone let me know if i can do this in hibernate?
 
Dave Tolls
Ranch Hand
Posts: 2091
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If they're the same structure then why have different tables?
 
Amritendu De
author
Ranch Hand
Posts: 188
11
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Dave. You can have Single table inheritance with 2 classes. Junior and Senior could be the discriminator.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic