We help IT Professionals succeed at work.

Combination of JPA entity and Message Driven Bean

I want to create an entity bean which will pick some data from Topic on JMS Server and also some from database. JMS is publish and subscribe mode. And Persistence is from an RDBMS server.

I want to know if it is feasible or not.
How would its sequence and class diagram look like?
If so what are the limitations of this architecture?
Watch Question

jgdvishnuSoftware Architect


To give more insight on this.

I have trading website and there is Asset Table(or Entity) which stores list of companies and and type of asset such as (share/stock/Mutual Fund/Bonds).

We need to get the price for that asset from a JMS Topic and display to the user. So is there a way that the JPA Entity can also act as JMS Consumer or not.

What is the best way for the asset entity to fetch the Price from JMS Server.
Senior Engineer
To answer your question directly, there isn't anything that prevents you from having non-persistence methods in your entity class. Assuming you have a persistent Asset class you could theoretically code a getPrice method that creates a TopicConnection, a TopicSession and a TopicSubscriber to receive messages.

But I have the feeling I'm missing something here because I don't quite understand how you will "get the price for that asset from a JMS Topic". A Topic isn't a query mechanism. What I'm suspecting is that there is already a JMS Topic in existence where Asset prices are published for interested subscribers. Is that right? If so then what I think you want here is not for your entity class to try to interact with JMS directly but to have a separate JMS component in your design that subscribes to the Topic, receives the messages and stores the information somewhere (like the same Asset database) so that it can be retrieved through normal entity relationship navigation.

If you can fill in some of the gaps here I might be able to provide better assistance.

jgdvishnuSoftware Architect


Correct my understanding:-

I had the feeling that Message Driven Bean(MDB - Object) and Entity( EB -persistent object) are managed by application server separately in different pools.

If I mix both MDB and EB class feature into one class then I will not be using the application server's pool of objects feature.

Now to answer your question:-
Yes.  Asset prices are published for all stocks through a topic and I need to know the price for one or two of the shares at a time. Thus there is a need to persist the prices and query for that share.

The JMS Topic server will publish the new prices of all the stocks every few seconds and to store that in my local database and query them and then send to user the latest stock price will result in showing stale data as well as need to maintain huge database for storing transient stock data.

To have the best of both worlds I thought that I will put listeners on Asset entity and filter the message without storing the price all in real time.
jgdvishnuSoftware Architect


I've requested that this question be closed as follows:

Accepted answer: 500 points for jim_cakalic's comment #a37331569
Assisted answer: 0 points for jgdvishnu's comment #a37394900

for the following reason:

I feel that for some  part my understanding is correct.