I've been trying to figure this out for a while now and decided to ask your opinion.

I'm building several applications that share a common set of data and operations. Each application has specific data to add but there's a need to have a "bird's eye view" over the shared data supplied by the specific applications in the form of a, say, 'base' or 'fixed' web-app. The number of specific applications is (potentially) 20+ and some of them are only temporary (say 4-6 months).

When I just started out with this project (and in Java EE) I created an EAR, put the shared JPA entities and EJB's in an EJB project and added WARs as I went along. I used inheritence to add the specific data for each application. I soon ran into trouble because I couldn't get inheritance of entities to work over different EJB-projects so I ended up with one big EJB project containing all the entities and one database with table names prefixed with a string that identified the application: a situation I didn't like. Besides, the larger the project became the weirder the error messages became during development and having to delete all build and dist dirs and rebuild everything from scratch became tiresome (NetBeans 7).

So over time I decided to ditch the EAR and inheritance and switched to separate WARs and use a remote EJB to manage the shared data. The coupling web-app -> bird's eye view is realised through a local EJB calling the remote EJB and adding the shared data to locally defined entities so that for all intents and purposes it looks like the shared data is part of the local entity. I'm not quite happy with it because it seems too loosely defined for some reason and there's the matter of the added penalty on performance (which isn't too bad at the moment, but it might be in time).

I could go for a combination of the two (go back to EAR and switch the remote EJB to local ones but ditch inheritance) but then it's back to an unstable development environment. Besides, one little change in one of the applications means having to deploy everything. Somehow I'm thinking this will lead to trouble someday (e.g. breaking not 1 but 20+ applications at the time..)

How would you do it and why? Does anybody have any experience with projects of comparable size and how did that go during development (i.e. experience any issues as the project grew)?

1 Answer
1

Don't ditch the inheritance. Use it, but instead of entity EJBs just
with POJOs packaged in a separate jar file. Have all your EJBs
deployed in a separate(large) EJB project.
Let these EJBs expose RESTFul WS.

The Webapps makes REST calls to the EJB Project. EJB
entities pull the data, populate POJOs and convert it to JSON(or XML)
and send it to the WebApp.

The WebApp recreates the POJOs using the
serialized JSON object and use it in the WebApp. These POJOs are kind
of Data Transfer Objects..

Thank you for your answer. I had been thinking about using either WS or RS but decided against it figuring using remote EJB's accomplished essentially the same with less overhead and a more 'natural' programming scheme. Do you mean having application specific entities (using inheritance) defined in the one and the same EJB project?
–
Daan de ZwartMar 15 '12 at 8:44