Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the EJB 3.0 version of method ejbCreate

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.

like image 837
Stefan Avatar asked Dec 28 '22 12:12

Stefan


2 Answers

@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.

like image 128
Tomasz Nurkiewicz Avatar answered Jan 12 '23 23:01

Tomasz Nurkiewicz


You need to use EJB 3.0 lifecycle callback methods using annotations

@PostConstruct, @PreDestroy, @PostActivate or @PrePassivate

These annotations can go on any method that is public, void and no-arg.

like image 30
Kal Avatar answered Jan 12 '23 23:01

Kal