Import and Export
From Taylor
Taylor Commons provides an Import/Export capability for JPA entities based on Betwixt.
Contents |
Betwixt
Betwixt is a framework for mapping JavaBeans to and from XML based on reflection. As such very little configuration is required, if any.
To support polymorphism, the src/main/resources/betwixt-config.xml file is generated per model with the necessary metadata.
Export
The export feature is available on all search screens. Use filtering to determine what will be exported. Then select the export action. This will open a new browser window to render the xml. Then use the browser's Save As menu to save the file to the desired location.
The export xml file will contain the entire entity graph.
Import
Manual
Each search screen has an Import action. This is usually restricted by an Admin role.
- Any entity can be imported from any search screen.
- TODO Create global import screen.
Automated
The net.taylor.seam.ImportInit component can be configured in a components.xml file to load multiple files at start up.
Annotations
Betwixt is just responsible for transforming the XML into JavaBeans.
Then there is logic necessary to determine if the entities need to be inserted, updated, or associated. This logic is provided by the net.taylor.seam.ImportUtil class.
Several JPA and Hibernate annotations provide the needed metadata.
@NaturalId
This Hibernate annotation identifies the business key that is used to look up each entity. If it does not exist it will be inserted.
@OneToMany, @OneToOne
These JPA annotations represent composition and will direct how child entities will be inserted or overwritten.
@ManyToOne, @ManyToMany
These JPA annotations represent references to other data. If the referenced data does not exist then it will be inserted. If it already exists then the existing entity will be associated with the imported entity.

