Should a stateful session bean implements Serializable
Asked Answered
M

2

7

I have a simple question but i can't find a answer for Java EE 6!

Should a stateful session bean implements Serializable or not?

I tested with and without implementing java.io.Serializable and there is no different and no errors.

My feeling tells me, that a stateful session bean MUST implements Serializable because it can be persisted in a long term session...

Moke answered 19/2, 2014 at 13:39 Comment(0)
V
4

No, it doesn't need to as the specification does not require that.

You may download and check the EJB specification from: https://jcp.org/en/jsr/detail?id=318

Valenta answered 19/2, 2014 at 13:39 Comment(4)
Ok, but why? Will it not be persisted?Moke
I think you misunderstand the meaning of 'stateful' here. It just means the bean maintains state between client calls. It does not mean the bean itself will be serialized to disk as java.io.Serializable.Valenta
There is a paragraph in the spec: "The container performs the Java programming language Serialization (or its equivalent) of the instance’s state (and its interceptors’ state) after it invokes the PrePassivate method on the instance and its interceptors.", as you can see, is the state + interceptors that are serialized.Wing
'State' is so vague though. Based on that description I'd say that the answer is then YES, the EJB bean itself needs to be Serializable or else its state couldn't be serialized when needed. Or do all the properties of the bean need to be Serializable in stead?Unboned
H
1

It depends how you are going to use it:

@Remote: Denotes a remote business interface. Method parameters are passed by value and need to be serializable as part of the RMI protocol.

@Local: Denotes a local business interface. Method parameters are passed by reference from the client to the bean.

Heteroplasty answered 19/2, 2014 at 13:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.