Skip to main content
Jump to: navigation, search

Difference between revisions of ""

Line 26: Line 26:
|apis= * [ JAXBHelper]
* [ JAXBContext (EclipseLink)]

Revision as of 11:22, 17 June 2011

bugzilla id: rick.barkhouse (at)

committer id: rbarkhous

Location: Ottawa, Canada - Eastern Standard Time

  • Committer on Eclipse Persistence Services project - EclipseLink

Profession: Software Engineer

Currently working for Oracle Corporation on their TopLink product.

Also working with Eclipse Foundation on their EclipseLink product.

Mailing ListForumsIRCmattermost
OpenHelp WantedBug Day
Browse Source

Refreshing Metadata

EclipseLink MOXy 2.3 introduces the ability to refresh your JAXBContext's metadata at runtime. This allows you to make changes to existing mappings in a live application environment and see those changes immediately without having to create a new JAXBContext.

In order to use the Metadata Refresh feature, your metadata information must be provided as either Node(s) or MetadataSource.


Our example will be bootstrapped from the following EclipseLink OXM file:

<?xml version="1.0"?>
        <java-type name="Root">
                <xml-element java-attribute="name" name="orig-name"/>

Our JAXBContext is created in the standard way:

ClassLoader classLoader = ClassLoader.getSystemClassLoader();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputStream metadataStream = classLoader.getResourceAsStream("example/eclipselink-oxm.xml";
Document metadataDocument = db.parse(metadataStream);
Map<String, Object> props = new HashMap<String, Object>(1);
props.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, metadataDocument);
JAXBContext context = JAXBContextFactory.createContext(new Class[] { Root.class }, props);

At this point, if we were to marshal a Root object to XML, it would look like this:


For this example, we will modify the metadata Document directly to change the XML name for the name field. We can then refresh the metadata using the refeshMetadata() API:

Element xmlElementElement = (Element) metadataDocument.getElementsByTagNameNS("", "xml-element").item(0);
xmlElementElement.setAttribute("name", "new-name");

After refreshing metadata, the same Root object will be marshalled as follows:


Back to the top