wood burning stoves*
The moose likes EJB and other Java EE Technologies and the fly likes Static fields in Entity Bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Static fields in Entity Bean" Watch "Static fields in Entity Bean" New topic
Author

Static fields in Entity Bean

Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
Dear all
In EJB 2.0 Specification Chapter 24 p. 494, there is statement
"An enterprise Bean must not use read/write static fields. Using read-only static fields is allowed.
Therefore, it is recommended that all static fields in the enterprise bean class be declared as final."
What's the meaning of that statement especially about read/write static fields?
Example I have a static ArrayList variable, when I add some objects into that variable, is it true that I write static field?
thanks
daniel
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8904

Since EJB are distribued objects, only static final read only varialbles are allowed.
If you declare a Arraylist as a final static and modify the contents of the list you are viloating the spec because the arraylist in the same EJB in another JVM will *not* see the changes. So whenever using static avraibles use static final and for *read-only* purpose.
[ September 07, 2003: Message edited by: Pradeep Bhat ]

Groovy
Marin van Zandvoort
Greenhorn

Joined: Mar 04, 2004
Posts: 5
Hi,

I don't quite understand the spec's recommendation.
If declaring an object 'static final' doesn't prevent de object from being modified, I wouldn't be putting that phrase in the spec.

Am I perhaps missing something here?


MvZ
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150

Marin,
final prevents the reference from being modified. For some objects like Strings, this is enough. For other objects, you can call a set method and modify the object's state. Which doesn't meet the spirit of the final rule.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static fields in Entity Bean
 
Similar Threads
Please Explain....
EJBeans and static variables
final static variables in beans?
static field in bean class
Session bean