我正在阅读一本 EJB 3.1 书(O'Reilly、Andrew Lee Rubinger 和 Bill Burke),其中作者提到(这些不是书中的确切用词,这是我自己对文本的理解):
在 SFSB 中,当其被激活时(在钝化后)
pool),序列化对象与原始规范不同,不会返回
像 int 这样的默认值不保证返回 0 和 object
不保证返回 null
我的理解正确吗?如果这是真的,为什么 EJB 有这种行为?
原始帖子 http://www.coderanch.com/t/546765/java-EJB-SCBCD/certification/why-serialization-unpredictable-SFSB#2481285
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 the 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
发布评论
评论(1)
根据规范,仅适用于瞬态场。
从规范来看——O'Reilly 没有设计 EJB(只是说……):
“虽然容器不需要使用 Java 编程语言的序列化协议来存储 a 的状态钝化的会话实例,它必须达到等效的结果,唯一的例外是,容器在激活期间不需要重置瞬态字段的值。 [12] 宣布会议。一般来说,不鼓励使用 bean 的字段作为瞬态字段。” [EJB 3.1 - 4.2.1 - 强调我的]
编辑:
顺便说一句,你的问题的答案也在EJB规范中:
“对瞬态字段使用的限制确保容器可以使用Java序列化在钝化和激活过程中。”
EJB 3.1 规范(镜像/ pdf)
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)