• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help Required in Session Bean Interface

 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

@Stateful(name="mySessionBean")
public class SessionBean implements SessionRemote {

@Resource(name = "jdbc/sample1")
private DataSource jdbcSample1;
private Connection conn;
private String var;

public SessionBean() {
}

@PostConstruct
@PostActivate
public void init()throws Exception{
conn=jdbcSample1.getConnection();
System.out.println("Connection initilized");
}

public void getResult() {
var="SessionBean call";
}
public String getAnotherResult()throws Exception {
return var+" Another SessionBean call"+conn;
}

@PreDestroy
@PrePassivate
public void cleanup()throws Exception{
if(conn!=null)
conn.close();
System.out.println("connection destroyed");
}

@Remove
public void remove(){
jdbcSample1=null;
conn=null;
var=null;
System.out.println("remove called");
}
}
Above is code for Statefull Session Bean.
For above bean the SessionRemote interface should contain following methods
getResult()
getAnotherResult()

What about cleanup() and remove() methods,should i define theses methods in SessionRemote interface or not.
In case i have to define remove() method in SessionRemote interface
should i add @Remove annotation for remove() method in SessionRemote interface or not.

Thanks
 
Ram Venkat
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gowher Naik ,

Yes, you have to define clearnUp , Remove methods in Interface, no need to declate @Remove in interface.
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The cleanup() method is annotated as @PreDestroy and @Prepassivate is considered as life-cycle callback method, so no need to add in the business interface.

The methods (may be more than one with different names) annotated with @Remove are business methods and you must add them into business interface, if you want to call them. You have to call these methods annotated with @Remove explicitly in client codes. They are not called automatically by container. When you called one of the method annotated with @Remove the stateful bean instance is removed.

Hope this help

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic