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.
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.