File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

1 MDB and Session Bean

 
Myyron Murray Latorilla
Ranch Hand
Posts: 65
Eclipse IDE Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 321
IntelliJ IDE Java Spring
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
E Armitage
Rancher
Posts: 989
9
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
Eclipse IDE Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
Eclipse IDE Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
Eclipse IDE Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic