This week's book giveaway is in the Agile and Other Processes forum. We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line! See this thread for details.
Here is a question from www.ejbcertificate.com: Which of the following statements regarding an enterprise bean's environment are correct? 1. The container provides the tools that allow the deployer to create and manage the enterprise bean's environment. 2. Enterprise bean instances can modify the values of the environment entries at runtime. 3. The deployer sets and modifies the values of the environment entries by editing the enterprise bean's deployment descriptor. 4. Enterprise bean instances obtain the values of the environment entries from the enterprise bean's deployment descriptor. 5. Enterprise bean instances use the JNDI interfaces to obtain the values of the environment entries. The provided answer is 1 and 5, it says: Answers 3 and 4 are incorrect because the deployment descriptor is used to define only the environment entries, as opposed to the values that the enterprise bean expects to be provided at runtime. I am not sure what it means, why cannot we set and modify the values of the env entry?
Environment entries are designed to be deploy-time constants. They are not supposed to be deploy time variable initialization values. When you deploy your application and it has an <env-entry> in its deployment descriptor, the value is taken from the DD and put into the container's naming service to be looked up later. Thus, the value that you originally set your environment entry to is in your deployment descriptor AND in your naming service. If your ejb allowed you to modify an environment entry through your code, then the deployment descriptor env-entry value would not match the actual value that the bean would be looking up. Also, simply changing the value in the DD won't do anything unless you redeploy your application. Finally, the env-entry tag is for defining a constant that all instances of your bean type will use, like a static constant. If you allowed an instance to alter this value, the new value would be instance specific and not for the whole class to access. If you want something that varies, use instance variables or database record lookups and not env-entry.
At first look I would select 3 and 4 are both correct. But I would agree that the 3 and 4 are wrong if I look at this the question is about the run-time behaviour. Yes, the values is specified in the dd before it is depolyed and values are allowed to change before it is deployed. However after it is deployed DD Every thing in dd are transfered to JNDI context. DD is not in the picturre. Only look at this way, I will agree 3 and 4 are wrong. I wish there are less such question in the exam.