• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mapping problem - two tables, one entity

 
Rich Crawford
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all, I�m hoping for some assistance in figuring out how to implement a fairly complex mapping problem. Here is what I have to deal with in a legacy database situation (that I can't change - I have to adapt the mapping to):


1. Our current purchase order information is stored on a table called �PURCHASE_ORDER�.
2. Our older purchase order information is stored in an identical (structure-wise) table called �PURCHASE_ORDER_HIST�.
3. The primary key to these tables is PO_NUMBER and PO_SEQUENCE.
4. A given PO_NUMBER and PO_SEQUENCE will exist on either PURCHASE_ORDER or PURCHASE_ORDER_HIST, but not both.
5. The legacy applications that need to retrieve information for a given PO_NUMBER and PO_SEQUENCE have to query both tables to locate the information.


Using Hibernate as my persistence manager, I have an entity class called PurchaseOrder which I need to somehow map to BOTH tables and have the persistence layer automagically load the data. So far, I have only mapped this entity to the PURCHASE_ORDER table, and now need to figure out some way to also map it to PURCHASE_ORDER_HIST. My preference is to use annotations, but whatever it takes...

Basically, the persistence manager needs to query PURCHASE_ORDER, and if it doesn't find it there, query PURCHASE_ORDER_HIST. I'm currently just figuring out how to get it to load the correct entity; eventually, I'm going to have to try to figure out how get the persistence layer to update the correct table if an entity is changed.

Is this a scenario where some sort of Inheritance mapping could help?

Thanks for any help.
 
Mike Keith
author
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rich,

It sounds like you might be better served to make PurchaseOrder an abstract entity superclass and map the two tables each to different entity subclasses using TABLE_PER_CLASS strategy.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic