开发者

Stateful Session Beans don't get default values after deserialization

I was going through an EJB 3.1 book (O'Reilly, Andrew Lee Rubinger and Bill Burke), there the author is mentioning that (these are not th开发者_如何转开发e exact words in the book, this is my own understanding of the text):

in SFSB when its becoming activated (after coming out of passivated pool), serialized objects, unlike their original norm, will not return the default values like int will not guaranteed to return 0 and object is not guaranteed to return null

Is my understanding correct? If it's true, why EJB have this behavior?

Original post on http://www.coderanch.com/t/546765/java-EJB-SCBCD/certification/why-serialization-unpredictable-SFSB#2481285


Per spec that is only applicable to transient fields.

From the specifications -- O'Reilly did not design EJBs (just saying ...) :

"While the container is not required to use the Serialization protocol for the Java programming language to store the state of a passivated session instance, it must achieve the equivalent result. The one exception is that containers are not required to reset the value of transient fields during activation[12]. Declaring the session bean’s fields as transient is, in general, discouraged." [EJB 3.1 - 4.2.1 - emphasis mine]

edit:

Btw, the answer to your question is also in the EJB specification:

"The restrictions on the use of transient fields ensure that containers can use Java Serialization during passivation and activation."

EJB 3.1 spec (mirror/pdf)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜