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

Moderator: admin

Post Reply
deadlock_gr
Posts: 54
Joined: Tue Apr 19, 2011 10:32 am
Contact:

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

Post by deadlock_gr »

Typo:

onsider --> Consider

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Fixed.
Thanks for the feedback!
If you like our products and services, please help us by posting your review here.

perry

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

Post 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

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

PedroKowalski
Posts: 25
Joined: Thu Aug 04, 2011 10:36 am
Location: Poland
Contact:

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

Post 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!

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

PedroKowalski
Posts: 25
Joined: Thu Aug 04, 2011 10:36 am
Location: Poland
Contact:

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

Post 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.

Guest

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

Post 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.

Guest

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

Post 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?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

Ravi Bansal

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

Post 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 ?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

If the deployer wants to override, he should add env-entry-value.
-Paul.
If you like our products and services, please help us by posting your review here.

Fco_dAnconia
Posts: 1
Joined: Sat Apr 20, 2013 11:22 am
Contact:

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

Post 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?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

You are right. This option has now been marked as incorrect.
-Paul.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests