title: JAXB Factory for JPA entities
body: <p>In most of my previous projects I have two domain models, one with JAXB annotations and the other one with JPA annotations. I know they can combined into one model with both annotations in the same class, but in my experiences the tradeoffs with this approach always came to the conclusion to separate them. Another advantage of a separate approach is the ability to create the JAXB classes with a XSD and easily link in XSDs from other projects.</p>
  
  <p>In most cases I need factory classes being able for flexible creation of JAXB representations of my entities, e.g.</p>
  
  <pre><code>public class UserFactory
  {
    public UserFactory(User queryUser, String lang)
    {
       this.queryUser=queryUser;
       this.lang=lang;
    }
  
    public JaxbUser getUser(JpaUser jpaUser)
    {
       JaxbUser jaxbUser = new JaxbUser();
  
       if(queryUser.isSetId()){jaxbUser.setId(jpaUser.getId());}
       if(queryUser.isSetEmail()){jaxbUser.setEmail(jpaUser.getEmail());}
  
       if(queryUser.isSetRoles())
       {
         RolesFactory f = new RolesFactory(queryUser.getRoles(),lang);
         jaxbUser.setRoles(f.getRoles(jpaUser.getRoles()));
       }
       return jaxbUser;
    }
  }
  </code></pre>
  
  <p>I create a UserFactory with an individual template <code>queryUser</code> and the desired <code>lang</code> for entities supporting different languages. The template is checked during creation of the result for specific fields or additional factories and the resulting object is created. The query is defined in a XML file like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;query lang="en"&gt;
    &lt;user id="1"&gt;
      &lt;roles&gt;
        &lt;role code="code"/&gt;
      &lt;/roles&gt;
    &lt;/user&gt;
  &lt;/query&gt;
  </code></pre>
  
  <p>With this methodology I have a powerful and flexible tool to create customized XML, despite all drawback of maintaining two domain models and the factory classes. I know there are many frameworks or libraries available which I never have heard about, so here my question:</p>
  
  <p>Is there something available similar to my approach?</p>