Question

Im trying to migrate a stateful session bean from EJB 2.1 to EJB 3.0, the home interface of the bean which extends EJBHome has a create method with two args and the corresponding bean has a matching args ejbcreate method and one more no arg ejbcreate method. My question is- 1. do I need to create two constructors one no arg and one arg to migrate this stateful session bean? 2. The ejbcreate method code is throwing "CreateException" and a run time exception, as of now ejbcreate defines throws "CreateException", do i need to define thorws CreateException" on the constructor or can I skip the create exception throwing part in the code of the constructor.

Other alternative I see posted in one blog is creating a method and annotating with @init, though not sure if this is the way as they were talking about EJB2 client view for a EJB3 bean.

Was it helpful?

Solution

There is unfortunately no way to specify arguments while creating a stateful session bean using EJB 3, so you'll need to add an initialize(arg1, arg2) method and call it after obtaining in instance via JNDI.

Only the no-arg constructor can be used in EJB 3.

Yes, @Init is the equivalent of ejbCreate when using annotations to define the EJB 2 client view when using EJB 3 style bean definition.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top