Saturday, May 19, 2012

Ignoring fields in JPA with xml mappings

You've got a xml file that you need to persist to the database and you don't really want to use low level parsing and jdbc.
  • Use trang to create a xml schema for the xml files
  • Use xjc to create the java objects
  • Use jpa with xml mapping to persist so there's no need to touch the generated source form xjc.  For fields you don't care about map them as transient.. e.g.
     <entity class="com.domain.xml_1_0.Site" access="FIELD">
              <attributes>
                   <transient name="siteInternalId"/>
                   <transient name="siteLinkage"/>
                   <id name="siteId"/>
              </attributes>
       </entity>