Exporting XML catalog data using JPA.

exercise No. 42

Create comment in forum


In the section called “Reversing XML to Rdbms” you exported RDBMS data to XML by means of JDBC. In this follow up exercise JPA will be used facilitating the database reading part following:

  1. Import the following (standalone) Maven skeleton project into your workspace:

  2. Add required properties among with JPA annotations to de.hdm_stuttgart.mi.sda1.sql2catalog.model.Product and de.hdm_stuttgart.mi.sda1.sql2catalog.model.Description.


    Since Description instances are composites with respect to Product (Composition rather than aggregation or association) you might want to use @ElementCollection in favour of @ManyToOne and @OneToMany.


    Regarding ordering of descriptions you may want to read @OrderColumn's documentation.

  3. The Junit test class rdbms2catalog.TestSchema does contain JPA data inserting code being commented out. Having your data model completed you may un comment these. Test execution will then populate your database with sample data.

  4. Implement the actual RDBMS to XML export application.


    META-INF/persistence.xml does contain a second persistence unit strategy_none which does not alter the database schema. Since your tests already created a schema and inserted required test data you may use this alternate configuration for reading from your RDBMS data source.