Since a month ago i am studying restful web services really hard.
Now that i did practice the Syntax and i understand the concepts, i decided to make a very simple enterprise application that includes EJB, JPA and REST.
I am making a big effort in trying to understand what is the best way to organize this kind of system. Ill appreciate a lot if someone with experience in the field could give me some tips on what would be the best practice, and how can i solve my current problem.
Let me show you this image please. Sorry i cannot get better resolution(Use Ctrl+ Mouse Scroll Up to zoom):

As you can see this is a very simple enterprise app, that has 2 modules.
This application does not use CDI( I want to achieve my goal without CDI help and)
When some client(Any inter-operable client) sends a @GET with some parameters the REST service should pass those parameters to the EJB module which will search in the database and send back the appropiate data. At the end the service will automatically marshal with the help of JAXB and send the .XML back to the client.
My problems are the following:
- I get a ClassCastException because the entity in the that is in the EJB module is not compatible with the JAXB class in the WebModule(Even if their variables are the same)
- I don’t know how things should be organized so the front end can marshal and unmarshal those entities.
- Should maybe the entity class be in the front end combined with the JAXB mapping? If then, there will not be really need for the EJB module. But the thing is, i want the EJB module because i often do my CRUD operations there.
- What about exposing the EJB as a REST web service(making a hybrid)? Do you think this is a good idea? How can it help me?
- Again if i create a hybrid of JAXRS+EJB in the web module, i will must create then my JPA entities in the front end and that is a thing i never did before. Do you think it is a good practice?
- What do you suggest? What is often the way the Enterprise applications that use REST web services are organized?
Below is an example of a JAX-RS service implemented as a session bean using JPA for persistence and JAXB for messaging might look like. (note an
EntityManageris injected onto the session bean, why do you want to avoid this kind of behaviour?):If you want to use the same domain objects on the server and client side. Then I would provide the JPA mappings via XML rather than annotations to avoid a classpath depedency on the client.
For More Information
UPDATE
META-INF/persistence.xml
The persistence.xml file is where you specify a link to the XML file that contains the JPA mappings:
META-INF/orm.xml
It is in this file that you would add the XML representation of the JPA metadata.
For More Information