jakarta-eejsf-2ejbcdibacking-beans

JavaEE How to update View after Database Change


In my enterprise application, I'm trying to separate the Web Layer from the EJB Layer and deploy the corresponding files (jar and war) on two separate servers. Since I don't want to open a database session for every user who visits my application, I have a backing bean which stores a representation of the data in my database in memory. Everytime a user visits the application he sees only this data of the backing bean.

Now I have the problem that I must update this data whenever changes to the database are done. Until now I used CDI events for this. The EJBs would just throw CDI events when changes are made and the backing bean listened to these events and created a database session and updated its content.

Now that I want to deploy the web application and the EJB module on separate machines this will probably not work anymore since CDI events are limited to the same ear. I already tried deploying my whole ear module to one server and even then the events were not registered by the backing bean which is strange since this should work normally...

So now my question is : is there any other way than using JMS to update the backing bean data ? I would believe that this is not too much of an exotic use case but I can't find any information on how to deal with this problem.


Solution

  • You didn't specify which version of Java EE you are using - but if it is 7, then you have the WebSocket API at hand. You'll find an example of a non-browser-based Client Enpoint speaking with a Server Endpoint in Oracle WebLogic 12 documentation.

    Alternatively, you could implement a RESTful Web Service in you web application, which gets called by your business application in order to notify you for updates.