Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Help Required in Session Bean Interface

 
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
 
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.
 
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
    Bookmark Topic Watch Topic
  • New Topic