• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

why ejbCreate can't be invoked?

 
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello
i want to do some initial operation when the session bean is first created,but where my initial code should be?i think it should be "ejbCreate()" method,so that i make the following test:
the ejbCreate method of my session bean:

public void ejbCreate() throws CreateException {
System.out.println("this is ejbCreate!");
}

then i write a test client by using the jb6 test client wizard,in the test client,i invoke the create() method of the home interface of the session bean,i think that the ejbCreate method should be invoked,but it can't,the code snippet as:

.....................
Context ctx = new InitialContext();
Object ref = ctx.lookup("session");
sessionHomeObject = (sessionHome) PortableRemoteObject.narrow(ref, sessionHome.class)
session s=sessionHomeObject.create();
.........................
.............

when i execute the test client,the string "this is ejbCreate" can't be printed,but i can call any business method of the session bean in the client,i wonder when the ejbCreate method is executed?how can i do some initialization operation,because the session bean has not the constructor.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I don't think so it will not call ejbCreat(),
It will call. noramlly we have to Create the PK ID in the ejbCreat() method is self..
here is the samle code
ProductEJB.java
=========================================
public String ejbCreate(String productId, String description,
double price) throws CreateException {
if (productId == null) {
throw new CreateException("The productId is required.");
}
this.productId = productId;
this.description = description;
this.price = price;
return null;
}
=======================================
ProductHome .java
=======================================

public interface ProductHome extends EJBHome {
public Product create(String productId, String description,
double balance) throws RemoteException, CreateException;

public Product findByPrimaryKey(String productId)
throws FinderException, RemoteException;

public Collection findByDescription(String description)
throws FinderException, RemoteException;
public Collection findInRange(double low, double high)
throws FinderException, RemoteException;
}
=======================================
Client
=======================================
public class ProductClient {
public static void main(String[] args) {
try {
Context initial = new InitialContext();
Object objref = initial.lookup("jdbc/Cloudscape");
ProductHome home =
(ProductHome)PortableRemoteObject.narrow(objref,
ProductHome.class);
Product duke = home.create("123", "Ceramic Dog", 10.00);
}
}
=======================================

I think it helps you..but i'm sure it will call ejbCreat methoid..check out..
viswa
[ April 04, 2002: Message edited by: viswagb ]
 
What? What, what, what? What what tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic