Page 1 of 1

About Question enthuware.oce-ejbd.v6.2.379 :

Posted: Tue Oct 09, 2012 6:01 pm
by ETS User
Could you please clarify (perhaps, to add it to the answers explanation) - what will happen to the resource injection for "private string ds"?

Since this injection is implied to be a success, I took it as a hint that the resource "ds_value" somehow exists in the context.

Re: About Question enthuware.oce-ejbd.v6.2.379 :

Posted: Mon Nov 12, 2012 8:08 am
by avoodoo
It is also interesting for me....

Re: About Question enthuware.oce-ejbd.v6.2.379 :

Posted: Mon Nov 12, 2012 12:42 pm
by admin
The resource injection for "private String ds" will not happen but it will not result in an exception because as per section 16.4.1.3, it is possible to provide a default value for a field and the deployer may choose not to override it. However, in such a case, the name is not available in the local JNDI environment of the bean. Therefore, the lookup call will throw an exception in this case.

HTH,
Paul.

Re: About Question enthuware.oce-ejbd.v6.2.379 :

Posted: Fri Nov 23, 2012 12:17 pm
by Ravi Bansal
Ejb 3.1 Specs , Section 16.2 Point 1
The enterprise bean makes use of entries from the environment. Entries from the environment may be injected by the container into the bean’s fields or methods, or the methods of the bean may access the environment using the EJBContext lookup method or the JNDI interfaces. The Bean Provider declares in Java language metadata annotations or in the deployment descriptor all the environment entries that the enterprise bean expects to be provided in its environment at runtime
Doesnt this mean that Environment Entries can be declared using annotations as well (without deployment descriptor) ?

Re: About Question enthuware.oce-ejbd.v6.2.379 :

Posted: Fri Nov 23, 2012 12:52 pm
by admin
Ravi Bansal wrote:Ejb 3.1 Specs , Section 16.2 Point 1
The enterprise bean makes use of entries from the environment. Entries from the environment may be injected by the container into the bean’s fields or methods, or the methods of the bean may access the environment using the EJBContext lookup method or the JNDI interfaces. The Bean Provider declares in Java language metadata annotations or in the deployment descriptor all the environment entries that the enterprise bean expects to be provided in its environment at runtime
Doesnt this mean that Environment Entries can be declared using annotations as well (without deployment descriptor) ?
Yes, it can be. But I am not sure what is your point.
-Paul.

Re: About Question enthuware.oce-ejbd.v6.2.379 :

Posted: Sat Nov 24, 2012 9:03 am
by rkbansal83
I assumed the statement implies that @Resource annotation will register ds_value the in JNDI
namespace (as no deployment descriptor is available), but seems that I was wrong

The Point is if this @Resource does not register the env entry in the Name Space to make it available for look ups, then what is the use of this type of injection (the one we have in question) as this member variable "ds" is anywaz accessible in member methods of bean class ?

Re: About Question enthuware.oce-ejbd.v6.2.379 :

Posted: Sat Nov 24, 2012 10:22 am
by admin
The point of using @Resource is to inject the resource into the variable. You don't need to "look up" anything once your variable is already injected with the right object. You can, if you want to, though. Please check out the various attributes of this annotation.

HTH,
Paul.

Re: About Question enthuware.oce-ejbd.v6.2.379 :

Posted: Fri Feb 08, 2019 3:24 pm
by henrid
In various documents I read that @EJB and @Resource declare things in the environment namespace to be looked up. So those documents are wrong? So entries in the deployment descriptor are always needed to be used by @EJB and @Resource? Or does it differ depending on putting annotations on class or property level?

Re: About Question enthuware.oce-ejbd.v6.2.379 :

Posted: Sat Feb 09, 2019 2:56 am
by admin
Can you provide a reference to the document(s) that you are referring to?

Re: About Question enthuware.oce-ejbd.v6.2.379 :

Posted: Sat Feb 09, 2019 12:00 pm
by henrid
For example: "Enterprise JavaBeans 3.1 by O'Reilly" page 257:
The ENC’s JNDI namespace is populated in two separate ways: via XML or via annotations. Any reference that you declare in XML to a service or resource automatically populates the JNDI ENC with the reference’s name. Any environment annotation that you use in your bean class also causes the ENC to be populated. Once an item is bound to the JNDI ENC of the EJB container, it can be referenced by a JNDI lookup.
Each referenceable type also has a corresponding annotation that can be used as an alternative to XML. If you specify these annotations on the bean class, they will cause the JNDI ENC to be populated with the information defined in the annotation

I can imagine that this behaves differently for different types of resources, and that you need a value in XML for simple environment entries, but this confuses me. And this text also describes the point about annotation level, on class or not. But okay, I will remember that XML is needed.

Re: About Question enthuware.oce-ejbd.v6.2.379 :

Posted: Sat Feb 09, 2019 12:11 pm
by admin
Both are talking about two different things. To set the value of a variable using @Resource annotation, you need to specify the name of an entry that already exists in the name space. This is the name that is given in the name attribute of @Resource. This is not the name by which the object pointed to by this variable will be set in the name space. This what I mentioned in one of my responses above.

Check out all the attributes of @Resource annotation to understand how to set an entry into name space instead of just looking up an entry.