users@jaxb.java.net

Entity (JPA)/OO focused JAXB?

From: Steven Siebert <smsiebe_at_gmail.com>
Date: Fri, 18 Jun 2010 01:47:20 -0400

Hello,

I did some searching through the archives, learned a bit about hyperjaxb2/3,
but I still haven't found the right solution for what I'm wanting to do
(perhaps it's simply I'm not grokking).

What I want to achieve is the ability to maintain my domain model, ORM, and
other various serializations right in my Java code (with the ability to
override in XML descriptors, of course). The idea is that I would have a
centralized place to maintain the code/documentation and generate said
documentation and additional artifacts directly from the code. This differs
from what I have seen with the likes of hyperjaxb - the goal of which seems
to be generating Java artifacts from XML schemas and annotate them with JPA
annotations (I want to go the other way, I suppose).

Currently, I'm focused on an EE/Web Service project (EE6/GF3.0) where I have
JPA2 entities that model my domain annotated with both JPA and JAXB
annotations. For the most part, I can simply expose my Entity classes as
arguments or result objects in my SLSB/Web Services web methods with crafty
use of JAXB annotations. Using Jersey/JAXB, my XSDs and WSDLs are generated
for me at deployment and looks pretty good. (Likewise, I look forward to
GF3.1 release which will provide better JSON support via JAXB). Please
note, I'm going through Jersey...I probably could do some fancy work with
the marshaling/un-marshaling process...but I'm not really sure how that
would muck with Jersey. Plus, I don't want to have to build external
classes to handle the XML process for an entity class - that kind of defeats
the purpose.

One problem I ran into today was supporting JPA idiosyncrasies, such as
embedded entities (for example: composite primary keys). These artifacts
don't really work as desired in JAXB - the schema is generated as if the
embedded entities are aggregated instead of...well...embedded. I looked
through the API and couldn't find an annotation (or otherwise) that would
let me do identify an "embedded" relationship such as exists with JPA. I
think adding an annotation such as @XmlEmbedded would be easy enough to
implement...but before I make a prototype, I want to ensure I'm not
recreating the wheel here (or my concept is just wrong in general). I also
considered the @XmlValue annotation and wondered if I could use this to
achieve the same...but I haven't had a chance to fully test and at 1:40am,
I'm just gonna send an email and try in the morning =).

I hope someone can point me in the right direction. I just started using
JAXB within the last 48-hrs...I'm a bit of a noob...so any suggestions are
appreciated. Also, if @XmlEmbedded is a welcome idea, I'll be glad to
contribute back.

Thanks!

Steve