About Question enthuware.oce-ejbd.v6.2.380 :
Moderator: admin
-
- Posts: 54
- Joined: Tue Apr 19, 2011 10:32 am
- Contact:
About Question enthuware.oce-ejbd.v6.2.380 :
Typo:
onsider --> Consider
onsider --> Consider
-
- Site Admin
- Posts: 10055
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.380 :
Fixed.
Thanks for the feedback!
Thanks for the feedback!
If you like our products and services, please help us by posting your review here.
Re: About Question enthuware.oce-ejbd.v6.2.380 :
how come it works? even without an <env-entry> element entry in ejb-jar.xml
but correct asnwer is
this prints "default"
running on glassfish3.1
but correct asnwer is
inside statful localbean, test() called from a servletAn <env-entry> needs to be defined in the ejb-jar.xml for this bean but it should not contain <env-entry-value> element.
Code: Select all
@Resource(name="none")
private String s = "default";
public void test() {
System.out.println(s);
}
running on glassfish3.1
-
- Site Admin
- Posts: 10055
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.380 :
Not sure how you tested but when I deploy the app, the deployment fails.
As per Section 16.4.1.3 - Declaration of Simple Environment Entries in the Deployment Descriptor
Paul.
As per Section 16.4.1.3 - Declaration of Simple Environment Entries in the Deployment Descriptor
The specification gives an example further:The Bean Provider must declare all the simple environment entries accessed from the enterprise bean’s code.
HTH,It is often convenient to declare a field as an injection target, but to specify a default value in the code, as illustrated in the following example.
// The maximum number of tax exemptions, configured by the Deployer.
@Resource int maxExemptions = 4; // defaults to 4
To support this case, the container must only inject a value for the environment entry if the application assembler or deployer has specified a value to override the default value. The env-entry-valueelement in the deployment descriptor is optional when an injection target is specified. If the element is not specified, no value will be injected.
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 25
- Joined: Thu Aug 04, 2011 10:36 am
- Location: Poland
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.380 :
Howdy!
Well I must say that I answered A in this question...
I've tested this example on Glassfish and it works fine without any <env-entry>. I attach the exemplary code tested below:
I think you're right that you need to provide the env-entry but ONLY if you want to access it using the JNDI. If you're using the value injected by the container, you don't need to use it. Just take a look at this part of the cited specification:
Cheers!
Well I must say that I answered A in this question...
I've tested this example on Glassfish and it works fine without any <env-entry>. I attach the exemplary code tested below:
Code: Select all
package com.test;
import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
@Stateless
@LocalBean
public class EnvTest
{
@Resource(name="ds_value")
private String ds = "HARDCODED";
public void saveData(){
System.out.println(ds);
}
}
What do you think about this?The env-entry-value element in the deployment descriptor is optional when an injection target is specified. If the element is not specified, no value will be injected. In addition, if the element is not specified, the named resource is not initialized in the naming context, and explicit lookups of the named resource will fail.
Cheers!
-
- Site Admin
- Posts: 10055
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.380 :
I am not sure what the element referred in "In addition, if the element is not specified, " is referring to - env-entry-value or env-entry.
But you may be right. As per section 16.4.1.3:
But you may be right. As per section 16.4.1.3:
Not sure why deployment is failing on Glassfish without this entry.The Bean Provider must declare all the simple environment entries accessed from the enterprise bean’s code. The simple environment entries are declared either using annotations in the bean class code or using the env-entry elements in the deployment descriptor.
If you like our products and services, please help us by posting your review here.
-
- Posts: 25
- Joined: Thu Aug 04, 2011 10:36 am
- Location: Poland
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.380 :
Howdy!
I've tested it on Glassfish 3.1 and JBoss AS7. It works in both cases. I attach the testing jar.
PS. I couldn't attach the *.jar file, so I've updated it here.
I've tested it on Glassfish 3.1 and JBoss AS7. It works in both cases. I attach the testing jar.
Cheers!13:06:14,802 INFO [org.jboss.as.server.deployment] (MSC service thread 1-6) Starting deployment of "EnvTest.jar"
13:06:14,819 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-8) JNDI bindings for session bean named EnvTest in deployment unit deployment "EnvTest.jar" are as follows:
java:global/EnvTest/EnvTest!com.test.EnvTest
java:app/EnvTest/EnvTest!com.test.EnvTest
java:module/EnvTest!com.test.EnvTest
java:global/EnvTest/EnvTest
java:app/EnvTest/EnvTest
java:module/EnvTest
13:06:14,884 INFO [stdout] (MSC service thread 1-2) HARDCODED
13:06:14,891 INFO [org.jboss.as.server.controller] (HttpManagementService-threads - 4) Deployed "EnvTest.jar"
PS. I couldn't attach the *.jar file, so I've updated it here.
Re: About Question enthuware.oce-ejbd.v6.2.380 :
"Nothing is required. No <env-entry> needs to be defined in ejb-jar.xml for this bean."
and therefore is answer
"An <env-entry> needs to be defined in the ejb-jar.xml for this bean if the value is to be accessed using JNDI but it should not contain <env-entry-value> element."
wrong.
and therefore is answer
"An <env-entry> needs to be defined in the ejb-jar.xml for this bean if the value is to be accessed using JNDI but it should not contain <env-entry-value> element."
wrong.
Re: About Question enthuware.oce-ejbd.v6.2.380 :
Maybe better make two separate questions with JNDI and without?Guest wrote:"Nothing is required. No <env-entry> needs to be defined in ejb-jar.xml for this bean."
and therefore is answer
"An <env-entry> needs to be defined in the ejb-jar.xml for this bean if the value is to be accessed using JNDI but it should not contain <env-entry-value> element."
wrong.
-
- Site Admin
- Posts: 10055
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.380 :
Hello,Guest wrote:"Nothing is required. No <env-entry> needs to be defined in ejb-jar.xml for this bean."
and therefore is answer
"An <env-entry> needs to be defined in the ejb-jar.xml for this bean if the value is to be accessed using JNDI but it should not contain <env-entry-value> element."
wrong.
As the explanation says, "Therefore, if you are not accessing a value through JNDI lookup, you do not require the env-entry in the deployment descriptor for this value."
So for the given code it is correct.
The other option is saying, "...if the value is to be accessed using JNDI ...". So this is also a correct statement.
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.380 :
An <env-entry> needs to be defined in the ejb-jar.xml for this bean if the value is to be accessed using JNDI but it should not contain <env-entry-value> element.
I did not understand , why the statement says to have env-entry without <env-entry-value> element ?
If we wont have <env-entry-value>, how will deployer override the default value given by bean provider ?
I did not understand , why the statement says to have env-entry without <env-entry-value> element ?
If we wont have <env-entry-value>, how will deployer override the default value given by bean provider ?
-
- Site Admin
- Posts: 10055
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.380 :
If the deployer wants to override, he should add env-entry-value.
-Paul.
-Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 1
- Joined: Sat Apr 20, 2013 11:22 am
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.380 :
Therefore, any JNDI lookup will fail. How can "An <env-entry> needs to be defined in the ejb-jar.xml for this bean if the value is to be accessed using JNDI but it should not contain <env-entry-value> element." answer be correct?The env-entry-value element in the deployment descriptor is optional when an injection target is specified. If the element is not specified, no value will be injected. In addition, if the element is not specified, the named resource is not initialized in the naming context, and explicit lookups of the named resource will fail.
-
- Site Admin
- Posts: 10055
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.380 :
You are right. This option has now been marked as incorrect.
-Paul.
-Paul.
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 38 guests