Board index » jbuilder » Can not create CMP 2.0 bean

Can not create CMP 2.0 bean


2003-10-13 11:17:38 PM
jbuilder7
My prj has one CMP 2.0 entity bean "CheckingAccount" and one session
bean "Teller". In the Teller there is a openAccount(String name, float
deposit) (remote) to actually call CheckingAccount's interface to create
the account.
public void openAccount(java.lang.String name, float deposit) {
/**@todo Complete this method*/
try {
curr_account = checkingAccountHome_.create(name, deposit);
//error , throw exception
float amount = curr_account.getBalance().floatValue();
System.out.println("balance = "+ amount);
}
catch(CreateException e){
System.out.println("failed to open account"+e);
}
}
However, the openAccount in TellerBean will throw an exceptio when it
tries to create an account, reporting pass name(null),balance(null) to
the underlying SQL INSERT statement. Following is the ejbCreate code for
CheckngaccountBean, and the exception actually is thrown when ejbCreate
returns
abstract public class CheckingaccountBean implements EntityBean {
EntityContext entityContext;
public String name;
public float balance;
public AccountPK ejbCreate(java.lang.String name, float balance)
throws CreateException {
this.name = name; //ok
this.balance = balance; //ok
return null; //throw exception: can not INSERT (null, null) ...
}
}
Can anybody give me a hint?
Thanks
Danny Wang
 
 

Re:Can not create CMP 2.0 bean

In < XXXX@XXXXX.COM >Danny Wang wrote:
In your subject line, you mention that your are working
with EJB 2.0 specification beans. Yet, in the following
it would appear that you are not.
Quote
However, the openAccount in TellerBean will throw an exceptio when it
tries to create an account, reporting pass name(null),balance(null)
to the underlying SQL INSERT statement. Following is the ejbCreate
code for CheckngaccountBean, and the exception actually is thrown
when ejbCreate returns

abstract public class CheckingaccountBean implements EntityBean {
EntityContext entityContext;
public String name;
public float balance;

public AccountPK ejbCreate(java.lang.String name, float balance)
throws CreateException {
this.name = name; //ok
this.balance = balance; //ok
return null; //throw exception: can not INSERT (null, null) ...
} }
EJB 2.0 specifies _virtual_ persistence fields which are
accessible only via getter/setter methods. You don't
declare actual fields (such as String name, above) in
your bean class. (In EJB 1.0 and 1.1 you do, but not
in EJB 2.0+.) Try,
. . .
public AccountPK ejbCreate(java.lang.String name, float balance)
throws CreateException {
setName(name);
setBalance(balance);
return null;
}
// CMP field accessors -------------------
public abstract void setName(String name);
public abstract String getName();
public abstract void setBalance(float balance);
public abstract float getBalance();
. . .
Paul Furbacher [TeamB]
Save time, search the archives:
info.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.