aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes restriction on resource injection 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 "restriction on resource injection" Watch "restriction on resource injection" New topic
Author

restriction on resource injection

Sudarshan Sreenivasan
Ranch Hand

Joined: Jun 28, 2007
Posts: 188

Each resource may only be injected into a single field or method


Why this restriction ?
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
example-



Consider this above example, if there is no restriction, which one you will prefer as the Column name for the same instance field?


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

Joined: Jun 28, 2007
Posts: 188

Hi,
Thanks for you reply I kind of got the picture however I was inquiring why the restriction of injected the same resource into different fields of the same class.

I deciphered this restriction after reading the below section from Mastering Ejb 3.0.

Please correct me if i am wrong.

Each resource may only be injected into a single field or method for particular bean.If you need to use a resource in more than one spot in the bean class, you need to define that resource at the class level & then look it up explicitly by name
Karnati Sudhakar
Ranch Hand

Joined: Aug 26, 2008
Posts: 270

sid sree wrote:
Each resource may only be injected into a single field or method


Why this restriction ?


I found something related to this on the Sun blogs and quite nicely explained there.Eighth point in this blog.

Regards
Sudhakar


Regards
Sudhakar
Sudarshan Sreenivasan
Ranch Hand

Joined: Jun 28, 2007
Posts: 188

Thanks a lot i think the blog was superb however it still has not answered my question.

I have elaborated on it in my previous post.Will be grateful if someone could clarify it. :?:


Thanks
Sudarshan
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

Hi guys,

I think that behind this affirmation is the JNDI or more precisely what happen when a resource is injected - the EJB container bounds the injected resource with a name. So if you inject the same resource two time you have the bound two times for the same resource and this can lead to confusions. Is similar with the code :


you will have two variables which are pointing to the same thing.

If you do a look up(how is suggested) then you'll use this mapping (which is doned only one) how many times you need it.


Regards,
M


SCJP, SCJD, SCWCD, OCPJBCD
Sudarshan Sreenivasan
Ranch Hand

Joined: Jun 28, 2007
Posts: 188

String Myname = "sid";
String Myname1="sid";


I think the above resembles more closely what i am trying to ask.

What if the same resource is injected into 2 different fields of the same class ??

Why is this no permitted ??
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

hi Sid,

Pretty fast answer, I don't think that this is more not "desirable". The DI mechanism is triggered two times and second time is not justified because in the bean context the resource already exist (with a certain name).
Why you think that this is not permitted ?

Regards,
M
Sudarshan Sreenivasan
Ranch Hand

Joined: Jun 28, 2007
Posts: 188

Hi,

I guess its not desirable but i was asking this from the exam point of view it should however be allowed i think.

However the quote above implies that it is not allowed :?:

Any thoughts on this ??
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

Hi

Desirable = you can do it if you consider but this can have some latter consequences.
I'll do a test, latter, to see if this is really a bad technique or a "not allowed" stuff.

Regards,
M
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: restriction on resource injection