What is the EJB 3.0 version of method ejbCreate

Stefan picture Stefan · Oct 27, 2011 · Viewed 12.3k times · Source

I would like to migrate some old EJB 2.1 code to EJB 3.0, but there is some handling of configuration errors in the ejbCreate method. Is there an EJB 3 version of that method?

Edit: In EJB 2.x ejbCreate could throw a CreateException. Based on the documentation of @PostConstruct etc. I can no longer throw any checked Exceptions. How can i handle this if i cannot migrate the code using the EJB right now.

Edit2: The frontend specifically handles CreateException which unfortunately is checked.

Answer

Tomasz Nurkiewicz picture Tomasz Nurkiewicz · Oct 27, 2011
@PostConstruct
public void anyName() {
    //initialization code, dependencies are already injected
}

No only the name is arbitrary, you can have several @PostConstruct methods in one EJB - however the order of invocation is unspecified, so be careful and try to stick with one method. UPDATE:

Only one method can be annotated with this annotation.