Page 1 of 1

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

Posted: Thu Apr 21, 2011 5:11 am
by deadlock_gr
Typo:

onsider --> Consider

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

Posted: Thu Apr 21, 2011 7:22 am
by admin
Fixed.
Thanks for the feedback!

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

Posted: Thu Aug 04, 2011 6:41 am
by perry
how come it works? even without an <env-entry> element entry in ejb-jar.xml

but correct asnwer is
An <env-entry> needs to be defined in the ejb-jar.xml for this bean but it should not contain <env-entry-value> element.
inside statful localbean, test() called from a servlet

Code: Select all

	@Resource(name="none") 
	private String s = "default";

 
	public void test() {
		System.out.println(s);
	}
this prints "default"

running on glassfish3.1

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

Posted: Thu Aug 04, 2011 9:34 am
by admin
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
The Bean Provider must declare all the simple environment entries accessed from the enterprise bean’s code.
The specification gives an example further:
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.
HTH,
Paul.

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

Posted: Mon Aug 08, 2011 6:24 pm
by PedroKowalski
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:

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);
    }
}
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:
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.
What do you think about this?

Cheers!

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

Posted: Wed Aug 10, 2011 5:43 am
by admin
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:
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.
Not sure why deployment is failing on Glassfish without this entry.

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

Posted: Wed Aug 17, 2011 6:11 am
by PedroKowalski
Howdy!

I've tested it on Glassfish 3.1 and JBoss AS7. It works in both cases. I attach the testing jar.
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"
Cheers!

PS. I couldn't attach the *.jar file, so I've updated it here.

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

Posted: Sun Nov 13, 2011 1:32 pm
by Guest
"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.

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

Posted: Sun Nov 13, 2011 1:35 pm
by Guest
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.
Maybe better make two separate questions with JNDI and without?

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

Posted: Sun Nov 20, 2011 9:48 pm
by admin
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.
Hello,
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.

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

Posted: Fri Nov 23, 2012 1:39 pm
by Ravi Bansal
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 ?

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

Posted: Fri Nov 23, 2012 2:15 pm
by admin
If the deployer wants to override, he should add env-entry-value.
-Paul.

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

Posted: Sat Apr 27, 2013 11:49 am
by Fco_dAnconia
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.
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?

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

Posted: Sat May 11, 2013 2:48 pm
by admin
You are right. This option has now been marked as incorrect.
-Paul.