0

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.

ajith
  • 5
  • 2

1 Answers1

0

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.

Brett Kail
  • 33,593
  • 2
  • 85
  • 90
  • thanks for the answer. I have a follow on question. Do I need to annotate the initialize (arg1,arg2) method with (@init). I feel since it is a normal pojo method call I dont need to annotate it. Also I dont have any EJB2 client view. – ajith Apr 16 '14 at 09:17
  • No. `@Init` is only applicable if you use the EJB 2 client view, and it is the method that will be called by the home.create(arg1, arg2). – Brett Kail Apr 16 '14 at 14:22