About Question enthuware.oce-ejbd.v6.2.379 :
Moderator: admin
About Question enthuware.oce-ejbd.v6.2.379 :
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.
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.
-
- Site Admin
- Posts: 10152
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.379 :
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.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
Re: About Question enthuware.oce-ejbd.v6.2.379 :
Ejb 3.1 Specs , Section 16.2 Point 1
Doesnt this mean that Environment Entries can be declared using annotations as well (without deployment descriptor) ?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
-
- Site Admin
- Posts: 10152
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.379 :
Yes, it can be. But I am not sure what is your point.Ravi Bansal wrote:Ejb 3.1 Specs , Section 16.2 Point 1
Doesnt this mean that Environment Entries can be declared using annotations as well (without deployment descriptor) ?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
-Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 33
- Joined: Sat Nov 24, 2012 8:52 am
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.379 :
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 ?
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 ?
-
- Site Admin
- Posts: 10152
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.379 :
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.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 31
- Joined: Sun Oct 13, 2013 1:20 pm
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.379 :
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?
-
- Site Admin
- Posts: 10152
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.379 :
Can you provide a reference to the document(s) that you are referring to?
If you like our products and services, please help us by posting your review here.
-
- Posts: 31
- Joined: Sun Oct 13, 2013 1:20 pm
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.379 :
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.
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.
-
- Site Admin
- Posts: 10152
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.379 :
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.
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.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 3 guests