aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes EJB 3 DI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "EJB 3 DI" Watch "EJB 3 DI" New topic
Author

EJB 3 DI

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9521
    
    2

Guyy,

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

@EJB
@Resource
@PersistenceContext
@PersistenceUnit


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 845
you are right...


SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
Jair Rillo Junior
Ranch Hand

Joined: Aug 27, 2008
Posts: 114
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).


Regards, Jair Rillo Junior
http://www.jairrillo.com/blog, SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 5.0, IBM SOA Associate (Test 664).
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9521
    
    2

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

Joined: Aug 27, 2008
Posts: 114
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

Joined: Sep 26, 2006
Posts: 9521
    
    2

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

Joined: Aug 27, 2008
Posts: 114
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

Joined: Sep 26, 2006
Posts: 9521
    
    2

Yes, it is better now. But why does EJB not allow us to inject POJO's while Spring does?
Jair Rillo Junior
Ranch Hand

Joined: Aug 27, 2008
Posts: 114
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

Joined: Aug 07, 2008
Posts: 94
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


SCJP(1.4), SCWCD, Oracle 9i SQL certified, Oracle PLSQL Developer Certified Associate
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9521
    
    2

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: EJB 3 DI