aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes 1 MDB and Session Bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "1 MDB and Session Bean" Watch "1 MDB and Session Bean" New topic
Author

1 MDB and Session Bean

Myyron Murray Latorilla
Ranch Hand

Joined: Dec 10, 2009
Posts: 65

If I only have 1 MDB instance, does it make sense to just instantiate the Session Bean class and not inject it. Given that both are packaged on a single EJB module project. Thanks in advance.
Palak Mathur
Ranch Hand

Joined: Jan 29, 2007
Posts: 313

But then it will just another Java object rather than a EJB. I am not sure though, however, I think if you are using it as an EJB then you should not do so. Will keep a watch on this topic.


Palak Mathur | My Blog | TechJaunt | What is JavaRanch? | List of All FAQs
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
myyron latorilla wrote:If I only have 1 MDB instance, does it make sense to just instantiate the Session Bean class and not inject it. Given that both are packaged on a single EJB module project. Thanks in advance.

Why was the session bean class made an EJB?
Does it have container services provided for it like being a target for injection, transaction management, security, managed resource access?
Those should have been the reasons used to make it an EJB. If it requires any of those then you lose those services if you instantiate it yourself.
If it doesn't use those services then it should never have been an EJB in the first place.
Myyron Murray Latorilla
Ranch Hand

Joined: Dec 10, 2009
Posts: 65

i think that would be the case on the method that i will call from the session bean in my single (max-pool-size = 1) MDB. Reason for having it 1 is that message needs to be processed serially.
Myyron Murray Latorilla
Ranch Hand

Joined: Dec 10, 2009
Posts: 65

hmmm, you are right on that sense, i guess the method needs to be moved out of the session bean then. But then, for the purpose of the topic, it is okay to instantiate than to inject for that purpose?
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10266
    
168

myyron latorilla wrote:But then, for the purpose of the topic, it is okay to instantiate than to inject for that purpose?


What exactly does instantiate mean? Are you talking about using the new() operator to do that? If yes, then never ever use the new() operator for "managed" components (like EJBs, servlets, managed beans etc...). Using the new() operator will just create instances of those classes as plain Java objects and they will not have any container managed capabilities.
Myyron Murray Latorilla
Ranch Hand

Joined: Dec 10, 2009
Posts: 65

i guess the answer for me is it is okay to instantiate (use new operator) for that sole purpose as the method doesnt need any container managed capabilities as i can always use the transaction management from the MDB. But then I wont do that, instead move the method out of the session bean. I hope you guys agree on this sense. thanks.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10266
    
168

myyron latorilla wrote: But then I wont do that, instead move the method out of the session bean.

Makes sense.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 1 MDB and Session Bean