Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3681832
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:43:48+00:00 2026-05-19T03:43:48+00:00

A java application I am working on has objects with a relationship similar to

  • 0

A java application I am working on has objects with a relationship similar to below. In the real application both objects are JPA entities.


class Underlying{}

class Thing
{
  private Underlying underlying;

  public Underlying getUnderlying()
  {
    return underlying;
  }

  public void setUnderlying(final Underlying underlying)
  {
    this.underlying = underlying;
  }
}

There is a requirement in the application to create xml of the form:

<template>
     <underlying>
        <thing/>
        <thing/>
        <thing/>
     </underlying>
</template>

So we have a situation where the object graph expresses the relationship between Thing and Underlying in the opposite direction to how it's expressed in the xml.

I expect to use JAXB to create the xml but ideally I don't want to have to create a new object hierarchy to reflect the associations in the xml. Is there any way to create xml of the form required from the entities in their current form (through the use of xml annotations or something)? I don't have any experience using JAXB but from the limited research I've done it doesn't seem like it's possible to reverse the direction of association in any straightforward way. Any help/advice would be greatly appreciated. One other option that has been suggested is to use XLST to transform the xml into the correct format. I have done no research on this topic as yet but I'll add to the question when I have some more info.

Thanks,

Matt.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T03:43:49+00:00Added an answer on May 19, 2026 at 3:43 am

    The trick is making a instance of Underlying aware of the related instances of Thing. Below are a couple approaches you could leverate.

    Option #1 – Make the Relationship Bidirectional

    The easiest thing to do would be to make the relationship bidirectional. Then you could leverage the @XmlInverseReference extension in EclipseLink JAXB (MOXy). Note: I’m the MOXy tech lead:

    • http://bdoughan.blogspot.com/2010/07/jpa-entities-to-xml-bidirectional.html

    Option #2 – Use an XmlAdapter

    You could create an adapted version of Underlying. When building the adapted Underlying object the XmlAdapter could query the instances of Thing to populate the things property:

    • http://bdoughan.blogspot.com/2010/07/xmladapter-jaxbs-secret-weapon.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone got EclipseLink MOXy (I'm using eclipselink 2.1.0) to work with Java 5?
I'm trying to write test harness for part of my Android mapping application. I
I am trying to understand the practical difference during the execution of a program
I was reading JavaScript: The Good Parts and the author mentions that JavaScript is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.