| Author |
EJB 3.1 with Java 6 how to presist the same object to two seperate tables
|
Piece OfChum
Greenhorn
Joined: Jan 14, 2013
Posts: 1
|
|
|
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.
|
 |
James Sutherland
Ranch Hand
Joined: Oct 01, 2007
Posts: 553
|
|
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
|
TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
|
 |
 |
|
|
subject: EJB 3.1 with Java 6 how to presist the same object to two seperate tables
|
|
|