• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static fields in EJB

 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can the EJB have static fields declared in the code?? Also the static blocks?? are they allowed in EJBs??

thanks
trupti
 
Vitaliy Geraymovych
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by trupti nigam:
Can the EJB have static fields declared in the code?? Also the static blocks?? are they allowed in EJBs??

thanks
trupti


EJB 2.0 Spec. Page 494. 24.1.2 Programming restrictions

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

So you can use static as a mean of declaring constants but not use it as a field which value can be updated by multiple bean instances. Therefore, static block would be illegal.

Vitaliy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic