« | »

JPA Database Import/Export Mechanism

21. August 2009

Provided you are already working with some JPA/Hibernate mapped Database, it would be very useful to have a generic and out-of-the-box working Database Import/Export mechanism at hand, which in the most generic case solely works on the JPA configuration/mapping already in place, for more sophisticated cases with some additional configuration. Such a mechanism should in my mind probably allow

  • To export the whole Database in a Vendor Unspecific, Java centric way and serialize it to some appropriate (probably XML-based) Data Format
  • To recover the whole Database to exactly the State represented in the Export.
  • To limit the Export to some Tables/Entities to be exported.
  • To make use of different Import Strategies when it comes to importing Entities into a non-empty Database. I think here of applying different Deletion Strategies – probably configurable per Entity Class – whenever importing instances of any given Class found in the Dump, cause I already stumbled upon practically applicable Use Cases for all of them:
    1. Deleting all (mapped) Entities in the Database.
    2. Deleting all Entities of the Hierarchy of the Class found in the Dump.
    3. Deleting all Entities of the Class found in the Dump.
    4. Deleting just the Entity found in the Dump itself.
    5. Not deleting anything, but just populating an eventually preexisting Entity found in the Database with the Properties found in the dumped Entity.
  • To alternatively base the “Identity” of a Dumped Entity not on it’s Database Primary Key, but on some configurable “natural” Key Values which can be found among its Properties.
  • To be aware of whether the Database Schema matches the Dump, and potentially also whether the Version of the Software working with the Data represented in the Database matches the Dump, and throw appropriate warnings and/or errors if not. (Maybe the desirable behaviour will depend on the requested Import Strategies for the Entities in the Dump.)
  • To be able to import Dumps produced with older versions of the Import/Export Tool itself.

A bit more investigation needed. It could turn out, that the basic features can be relatively easily achieved based on Hibernates XML serialisation format. Surely, we remember: nothing is as easy as espected. (On the other hand: exactly because of this truth we should also be wise enough not to expect everything to be difficult. Provided the statement “nothing is as easy as espected” is true, our expectations will influence how hard our time with an issue will turn out to be in the end. Won’t they? ;-)

(This post is part of my thoughts about A portfolio for Enterprise Web Applications)

« Spring Bean Instantiation for JPA/Hibernate | Deploy and upgrade like a breeze »

The URL to TrackBack this entry is: http://developing.schimak.at/2009/08/jpa-database-importexport-mechanism/trackback/

Leave a comment