wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Entity Bean unavailable to me Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Entity Bean unavailable to me" Watch "Entity Bean unavailable to me" New topic

Entity Bean unavailable to me

Mark Herschberg

Joined: Dec 04, 2000
Posts: 6037
I'm getting some very strange behavior with BMP entity beans.
The trading system I'm writing uses JMS for communication. A user will register with the system by creating a temporary queue, and setting that queue as the reply-to queue in it's registration message. The server will receive this message, and create an entity bean for each registered user. Unfortunately, because queues are not serializable, we can't put it in the database (at least, we think that's why CMP's weren't working). So we have a BMP that is stored in memory. Since we'll have maybe 200 users, this wouldn't be a big problem.
Prior Behavior
It's been working fine in that when the user placed a trade, a message with the results of the trade would be sent back to the user on the queue with which he logged in.
New Behavior:
We need to send each user what is effectively a personalized summary status report every 30 seconds, as well as when he logs in. It is sent using the same queue.
When the user first logs in, we send this summary on the queue, no problem. Then we have a thread which every 30 seconds, grabs all users from the DB, does some calc, and, for users who have registered, sends them the summary. For some reason, when I do the lookup on the EJB, I can't find the user. Despite giving a valid username (which works in other cases), I get an anonymous instance of the entity bean. But I use the same lookup code in both cases!
Here is some of the code. OrderUpdateQueueLookupTable is the entity bean (bad name, it was created when I was first learning about entity beans).
This is the method works, when a trade is executes

This method does not work

The method they rely on to do the lookup.

In the case where it doesn't work, the 3 field print statements in the 3rd method all have null values (anonymous instance), and so it apparently can't find the user. I've checked stupid things like making sure the username is correct, etc. They all seem to be in place.
Also confusing, the second method (sendEquityUpdate) does work in one case. When the user first registers, the entity bean gets created, and an equityUpdate gets sent (they happen within the same transcation, so maybe that has something to do with it). That does work. It just doesn't work when requested by the timer. I see the print statements, so I know the code is being called, it just things the user was never registered.
Two other notes. We only call remove when we first register (and then only if the user was already registered--basically, if you are already logged in on one computer, and log in on a second, the second overwrites the info about you being on the first computer). We also cache the beans: Entity Cache, cache between transactions = true, exclusive strategy.
Any ideas? This is baffling me.
[Broke up overlong line for readability - Jim]
[ March 11, 2003: Message edited by: Jim Yingst ]
Mark Herschberg

Joined: Dec 04, 2000
Posts: 6037
Hmm, further attempts to solve the problem revealed some unexpected behavior suggesting that maybe it's not the entity bean.
I replaced the Entity beans (meaning commented out calls to them) with a singleton Hashtable. Not the best design perhaps, but I just want to get something simple working ASAP.
But I'm having a similar problem. I add the user to the hashtable and it clearly has both the QueueSender and QueueSession in the table. I can pull them ok just fine. I then try to send a message to the queue. As before, when this is done in response to user-initiated action, such as placing an order, it works fine. When it is done as part of the update-every-30-seconds, it sends to the queue no problem, but my client never gets it from the queue. It's the same queue that had just worked before. Any thoughts?
Mark Herschberg

Joined: Dec 04, 2000
Posts: 6037
So I seem to be trying to do something similar to what Sun does in chapter 9 of the Java Message Service Tutorial. Anyone familiar with this? I still can't see anything I'm doing that's different and causing the problem.
Could there be some issue about sending JMS messages from independent threads on J2EE servers?
I agree. Here's the link: http://aspose.com/file-tools
subject: Entity Bean unavailable to me
Similar Threads
Message Driven Beans
Writing to a JMS Queue via Timer Method.
Server can't post to a TemporaryQueue created by the client
Resultset Not able to handle 200 records using JBOSS.
Problem in connecting to WebSphere MQ