• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB 3 DI

 
Joe Harry
Ranch Hand
Posts: 10080
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guyy,

When I say DI in EJB 3.0, does it make sense only for the following 4 annotations?

@EJB
@Resource
@PersistenceContext
@PersistenceUnit
 
Amandeep Singh
Ranch Hand
Posts: 850
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are right...
 
Jair Rillo Junior
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Different than Spring, where you can Inject any Java Object, EJB3 allows us to Inject objects using these Annotations. (Although for me they're enough).
 
Joe Harry
Ranch Hand
Posts: 10080
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You meant to say that we cannot inject POJO's using these EJB Annotations or what and Spring does allow injection of POJO's?
 
Jair Rillo Junior
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jothi Shankar Kumar Sankararaj:
You meant to say that we cannot inject POJO's using these EJB Annotations or what and Spring does allow injection of POJO's?


Yes. In Spring we can inject POJO. In EJB3 we cannot.
 
Joe Harry
Ranch Hand
Posts: 10080
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jair Rillo Junior:
Different than Spring, where you can Inject any Java Object, EJB3 allows us to Inject objects using these Annotations. (Although for me they're enough).


I did not get your line "EJB3 allows us to Inject objects using these Annotations" What do you actually mean by that? When I read this sentence in continuation with what you have written, I infer that we can inject POJO's using EJB 3 Annotations. Can you be a bit more clear?
 
Jair Rillo Junior
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Jothi, I wasn't clear.

in EJB3 you cannot INJECT POJO's. You can inject only EJB3 components and Resources components, but you CANNOT inject POJO or Java
class.

Supposing I have a simple POJO like this:


I cannot inject it using EJB3, because it isn't an EJB3 component. However, an Session Bean, like this one:


This one I can inject using the @EJB annotation.


Is it better now?
 
Joe Harry
Ranch Hand
Posts: 10080
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it is better now. But why does EJB not allow us to inject POJO's while Spring does?
 
Jair Rillo Junior
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jothi Shankar Kumar Sankararaj:
Yes, it is better now. But why does EJB not allow us to inject POJO's while Spring does?


Good question. I cannot answer it.

Using my experience with EJB3 so far, I've never had to INJECT a POJO directly. Hence, using only component injection are enough for me.
 
aleem khan
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the answer for your question:why EJB3.0 doesn't allow POJO injection

The whole point of EJB is to make distributable system, i,e one EJB can run on one server , other EJB on some other server... this is useful when there are lots of users say some 2000-20000 , if the whole EJB runs on one server the speed will be less or the server may crash... Now let us say EJB3.0 supports POJO (which is not EJB3.0 Component)... the POJO which has to be injected must be present in same server/JVM , otherwise it will throw exception... so to avoid all these complication we can inject only sessionbeans or datasource which can exist on any server...hope this helps your doubt
 
Joe Harry
Ranch Hand
Posts: 10080
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by aleem khan:
Here is the answer for your question:why EJB3.0 doesn't allow POJO injection

The whole point of EJB is to make distributable system, i,e one EJB can run on one server , other EJB on some other server... this is useful when there are lots of users say some 2000-20000 , if the whole EJB runs on one server the speed will be less or the server may crash... Now let us say EJB3.0 supports POJO (which is not EJB3.0 Component)... the POJO which has to be injected must be present in same server/JVM , otherwise it will throw exception... so to avoid all these complication we can inject only sessionbeans or datasource which can exist on any server...hope this helps your doubt


I'm not finding this satisfactory enough. Now I guarantee that I can place my POJO in the same JVM. Does this garantee be enough to inject it using EJB 3 DI? Your explanation does not justify the reason good enough.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic