Meaningless Drivel is fun!*
The moose likes Object Relational Mapping and the fly likes EJB 3.1 with Java 6 how to presist the same object to two seperate tables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "EJB 3.1 with Java 6 how to presist the same object to two seperate tables" Watch "EJB 3.1 with Java 6 how to presist the same object to two seperate tables" New topic
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: 2
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB 3.1 with Java 6 how to presist the same object to two seperate tables
 
Similar Threads
Data Conversion
Advantages of EJB 3/JPA over spring/hibernate
How to avoid duplicate inserts in JPA HQL (EJB 3.0 - Java EE 5)
Criteria across multiple tables
Spring 3.0 Framework, CAS and EJB