> -----Original Message----- > From: Andreas Veithen [mailto:[email protected]] > Sent: Sunday, December 13, 2009 2:38 AM > To: [email protected] > Subject: Re: Issues using same domain classes in JPA and CXF > > It should be noted that except for very simple cases, from an > architecture/design point of view, it is not a good idea to use the > same classes for JPA and JAXB. The reason is that this kind of > approach tightly couples the service interface (and thus the client) > to the underlying data model. This is no different from the good old > J2EE session facade pattern [1].
I'd say that there are some cases besides "simple" cases where this kind of architecture could be appropriate. In my situation, I have an existing database that is modeled with a somewhat legacy ORM layer, but there are existing applications that use that model. What I'm doing is designing domain classes that are similar to the existing resulting domain layer. This is what I need to provide access to in the REST layer. I could design a XML/JSON/JAXB layer that is arbitrarily different, but I see no point to that. However, I am "tweaking" the XML/JSON output slightly in the case of collections, to get reasonable XML wrappers. That's the only change I make. The point is to examine what interface the clients need. If they need an interface to an existing database and domain layer, then giving them that is the right approach. If this application was built from scratch, we would start with the interface and then design a domain layer to work with that, which would likely be different from the service interface, so your point would apply here. > > Andreas > > [1] > http://java.sun.com/blueprints/corej2eepatterns/Patterns/SessionFacade. > html > > On Sat, Dec 12, 2009 at 23:15, KARR, DAVID (ATTCINW) <[email protected]> > wrote: > > I'm building an app that retrieves data with JPA (OpenJPA right now) > and > > tries to serialize it in xml or json with CXF. I'm using annotations > on > > the domain class to specify both the logical JPA (not physical) and > JAXB > > behavior (with the physical JPA in XML config). In theory I would > think > > this should work, but in my first test I found that CXF didn't > serialize > > the object that I retrieved from JPA. > > > > After some thinking, I thought to write some debug code that prints > out > > the runtime annotations on the class, both for the class of the > returned > > instance, and the class that it's declared as. What I found (because > I > > realized I should have expected this) is that the runtime class > didn't > > have the required annotations that the declared class did. When JPA > > enhanced the classes, it didn't copy the annotations. I'm going to > ask > > about this on the OpenJPA list, but I was wondering if someone has > some > > experience with this kind of thing from the CXF/JAXB point of view. > >
