• Post Reply Bookmark Topic Watch Topic
  • New Topic

ejbLoad() - want to get value from Session Bean

 
Sunny Kiran
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

I have a problem, where i need to pass a value to ejbLoad() method in bmp, from the session bean.

As I know ejbLoad() method is invoked by application server, whenever we call findByPrimaryKey(), the only value which we pass (is a Primary Key) to findByPrimaryKey() is available to ejbLoad().

Can we get a value in ejbLoad() which is generated in Session Bean without passing it to findByPrimaryKey().



Help Me...

Thanks in Advance
[ November 16, 2005: Message edited by: Sunny Kiran ]
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kiran,


I have a problem, where i need to pass a value to ejbLoad() method in bmp, from the session bean.

You should not do this. The callback methods as their name stands should only be invoked by the container. Please review your design and find another solution to your problem. Eventually you can try to post here the issue you�re trying to address.

As I know ejbLoad() method is invoked by application server, whenever we call findByPrimaryKey(), the only value which we pass (is a Primary Key) to findByPrimaryKey() is available to ejbLoad().

As far as I know this might or might not be true. As per J2EE specs EJBs default to lazy loading. What this means is that the container will load the primary keys and will return the remote interfaces to the clients. If the client loops through the collection and start invoking any getters, the container will load the data from the database (remember the infamous n + 1 database calls with entity EJBs) and ejbLoad will get �lazily� invoked.

Can we get a value in ejbLoad() which is generated in Session Bean without passing it to findByPrimaryKey().

Now you lost me. Can you give here little bit more of business context and explain me what are you trying to achieve?
Regards.
 
Sunny Kiran
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tanase,

Ok, I will explain you clearly. I have a RequestId which is genarated each time while the user navigating thru JSP's. Here the controller will genarete the RequestId dynamically, which is a combination of IP address, UserName, Station, ModuleName, Operations and time. And this will be passesd to the Session Bean thru remote call, So that the requestId will be available to all methods, which are called from remote method.

Here I am getting probelm with ejbLoad() method as it is invoked by the container. Now my problem is to pass the generated RequestId to this ejbLoad(), so that RequestId will be avilable to the metods which are called inside ejbLoad(). I think, I am clear now.

Thanks in Advance...
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sunny Kiran:
Thanks Tanase,

Ok, I will explain you clearly. I have a RequestId which is genarated each time while the user navigating thru JSP's. Here the controller will genarete the RequestId dynamically, which is a combination of IP address, UserName, Station, ModuleName, Operations and time. And this will be passesd to the Session Bean thru remote call, So that the requestId will be available to all methods, which are called from remote method.

Here I am getting probelm with ejbLoad() method as it is invoked by the container. Now my problem is to pass the generated RequestId to this ejbLoad(), so that RequestId will be avilable to the metods which are called inside ejbLoad(). I think, I am clear now.

Thanks in Advance...


You cannot pass data to the ejbLoad() directly.
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kiran,

Hi Sunny,

I do understand your problem, but you have to understand that sometimes things are simply not going to work the way we want. For the argument sake let�s assume that we really intend to pass an argument to ejbLoad(). From your posting, since you need to make the requestId available to other methods inside ejbLoad(), I�ll assume that you�re using BMP. This being the case, you have to ways to pass the requested:
  • Either indirectly by simply updating the table your bean is mapping to. This implies that you should have a column requestId that will get updated before loading the bean.
  • Either directly by having an instance variable on the bean class and providing appropriate setter/getter methods. In this scenario you first call the getter from your session bean to set the requestId and finally call the getter inside of ejbLoad().


  • I guess 1 is out of any discussion, since it doesn�t make much sense from a design point of view. 2 on the other hand, might look promising, but it cannot be achieved because you never know when the container will actually call the ejbLoad. You also have no control over the instance that gets updated when calling the setter in the first place. That�s the problem with the callback methods: developers have no control over the way or time they are called.
    Your problem on the other hand should be better modeled inside the business logic. Once you passed the requestId to the session fa�ade, you should be able to pass this parameter to every business method without the need of re-loading it through entity ejbs. You see, my dilemma is this: you generate the requestId in the presentation layer, which is ok. You pass it to the business layer, which again is ok. Next you need your persistence layer to re-load it from the database(?!) Why? It doesn�t make much sense to me.
    Bottom line is that you should reanalyze your use case and come up with a better solution to your problem. Again this is just my opinion�
    Regards.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!