Friday, June 10, 2011

Extend your Persistence Unit on the fly

Imagine a system that keeps track of player statistics in a sports league. Personal information such as name, height, weight and basic statistics such as the number of games played is stored for all players.

A persistence unit is deployed with all the mappings described above.

The system admin of a basketball league wants to use the system and add mappings for points scored and fouls. As the system is running they tell EcliseLink about mappings for those fields and the next EntityManager they get uses them.

Starting with EclipseLink 2.3, you can do just that. To do that, all you have to do is:

- Build a traditional persistence unit
- Tweak your Entities so they can hold added mappings
- Build room for additional data into your database schema
- Define a repository to contain your additional mappings and tell EclipseLink about it

With those steps, any EntityManager created from your persistence unit will use your new mappings.

Additionally, you can refresh your EntityManagerFactory. Any EntityManager created after the refresh will use any new mappings added to the repository since the previous refresh.





The following link shows an example of how a system as described above could be configured. Please note: The final release date for EclipseLink 2.3 is June 22, 2011 and the examples and documentation will evolve as we get closer to that date. If you would like more detail, please check back after the release date or take advantage of our mailing lists and forums.

http://wiki.eclipse.org/EclipseLink/Examples/JPA/Extensibility

No comments: