Is the @Resource annotation applied when a Stateless EJB is deserialized?
Asked Answered
K

1

6

Is the @Resource annotation on a method applied when an EJB is deserialized? I have a EJB Timer thats persisted by the container and would like to know if the transient TimerService (it's not serializable) will be injected again when the EJB is deserialized.

Kukri answered 24/11, 2010 at 11:0 Comment(4)
Excellent question. No idea what the answer is…Homologue
do you mean "activated" (after passivation) ?Anett
I think it won't be hard to try it.Anett
@Anett - Its a Stateless beanKukri
B
3

Perhaps this articles help:

  • Stateless Session Bean: the stateless session EJB is injected at creation time, and keeps it's resources along its life time.

  • Stateful Session Bean: It seems that the dependency injection only occurs at creation time. Anyway, after activation, the @PostActivate callback Handler is invoked, where you could recover your transient elements.

Edit for adding the Java EE Tutorial link on this subject, which confirms what is exposed:

So, as a conclusion, the answer is no, the container won't inject again your transient resources after activation, but you can implement a PostActivate handler to do it by your own means.

Babiche answered 24/11, 2010 at 13:20 Comment(1)
Thanks for the JEE tutorial link. On Stateless Beans (download.oracle.com/javaee/5/tutorial/doc/bnbmt.html#bnbmw) Because a stateless session bean is never passivated, its life cycle has only two stages: nonexistent and ready for the invocation of business methods. The Timer EJB is most likely serialized so that it can exists across server restarts. However when its needed a and not available, new instance is always created, and dependency injection will work.Kukri

© 2022 - 2024 — McMap. All rights reserved.