Question: how to bind SOAP ORM JPA ?
Few days evaluating my options about binding my SOAP message
objects to my JPA entities.... I have:
|A soap serializable type, let's say
||A JPA entity type, let's say
As you can deduct from the short code samples, every time my
web-service receives a SOAP message containing values that should be
persistent in the database, I should convert the received objects to the
JPA entities. And every time I read the data base to respond a
service request, I should convert the read entity in the respective
object that can be serialized in the SOAP messages. A dual channel
repetitive copy mechanism - a copy layer - or binding framework. I don't
like the term
binding since the objects not only differs in
format but the objects are part of completely different models - this is
another topic I prefer to skip here.
Questions: How to copy the values between the SOAP Message
elements and the JPA entities?
Options I am considering right now:
- Brute force, copying one by one the fields
and properties from one side to another. Simple, fast and the most
reliable solution, but with a lot of identical code for all entities.
The number of line codes required to copy is linearly coupled with the
number of entities and their attributes (can be thousands of lines to
code and maintain).
- Recursive Reflection: trying to match the
getters and setters names.. it works fine for shallow copy but becomes
weird with collections and nested complex types. Reflection reduces
the number of lines and, depending on the simplicity of the models, can
be a good option. You pay a bit of performance but in my early
experiments, the cost/benefit of reflection is good. href='http://dozer.sourceforge.net/'>Dozer is a nice option here
but it imposes quite a lot of dependencies and seems Spring oriented -
so, if you are using Spring, go for it.
- Adapters using annotations: similar to the
solution proposed href='http://tssblog.blogs.techtarget.com/2007/02/08/combining-orm-and-soap-part-1/'>here,
but instead of mapping XML to Objects I plan to map different objects
(from different models).
- Inheritance between the soap objects and
entities: entities are declared subclasses of XML generated objects,
so I need to copy only from xml to entites, the reverse order is
naturally bounded by casting. What means you solve half of the problem
:). This points to an unwanted coupling between the models, but reduce
the processing effort, so the bargain between the beauty and the power
is up to you.
I certainly will blog here if I find a good workaround to this
problem, so I hope to hear from you something new :)
* This is a reviewed text of
same question I posted few days ago on the Metro forum. So, feel free to
offer your wisdom here or in the forum.