• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

EJB 3.1 with Java 6 how to presist the same object to two seperate tables

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello I am upgrading a legacy application to use EJB 3.1/JPA2.0. The current application uses EJB 2.x BMP beans for persistence. I have been successful in my implementation but have run into one issue that has been a bit of a pain. The issues is that my legacy application stores an object into two separate tables. I want to know if it is possible to use the same POJO and map it slightly differently in two separate tables. Currently the application decides which table to pull the entity from based on the user type. I know this is a bogus design however the application is far to large to change this right now the plan is to eventually redesign parts of the database.
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have two tables with the same schema, I would use inheritance to map them. Either a @MappedSuperclass, or TABLE_PER_CLASS inheritance.
So you would have two subclasses, one for each table, and decide which subclass to read based on the same condition you are currently using.

See,
http://en.wikibooks.org/wiki/Java_Persistence/Inheritance
 
It's exactly the same and completely different as this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic