精通EJB(第三版)第七章-开发Bean管理持久化实体Bean例子(BankAccount)的部署问题!

各位大虾:
我在学习精通EJB(第三版)第七章-开发Bean管理持久化实体Bean的实例时,使用Eclipse-Jboss-IDE开发该例子(银行帐户),应用服务器为JBoss-4.0,数据库为Mysql,当我将例子打包为AccountEJB.jar文件后,将其部署至JBoss服务器时,服务器报错信息如下:
13:32:36,078 WARN [verifier] EJB spec violation:
Bean : Account
Method : public AccountPK ejbCreate(String, String) throws CreateException
Section: 12.2.3
Warning: The return type must be the entity bean's primary key type.

13:32:36,078 WARN [verifier] EJB spec violation:
Bean : Account
Section: 12.2.5
Warning: Every entity bean must define the ejbFindByPrimaryKey method.

13:32:36,078 WARN [verifier] EJB spec violation:
Bean : Account
Method : public AccountPK ejbFindByPrimaryPK(AccountPK) throws FinderException
Section: 12.2.5
Warning: The return type of a finder method must be the entity bean's primary key type, or a collection of primary keys (see Specification Section 12.1.7)

13:32:36,078 ERROR [MainDeployer] could not create deployment: file:/D:/java/java/jboss/jboss-4.0.2/server/default/deploy/AccountEJB.jar
org.jboss.deployment.DeploymentException: Verification of Enterprise Beans failed, see above for error messages.
at org.jboss.ejb.EJBDeployer.create(EJBDeployer.java:553)
at org.jboss.deployment.MainDeployer.create(MainDeployer.java:918)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:774)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:738)
at sun.reflect.GeneratedMethodAccessor50.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:121)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:127)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:249)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
at $Proxy8.deploy(Unknown Source)
at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:325)
at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:501)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:204)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:215)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:194)
请各位大虾帮忙看看,不胜感激!送100分!!
[3058 byte] By [yianhuang] at [2008-1-6]
# 1
怎么没回复啊?各位大虾没有调试过吗?恳请大虾赐教!
yianhuang at 2007-10-28 > top of Msdn China Tech,Java,J2EE,EJB,JMS...
# 2
数据库相应表的主键建了么?
wantsong-WantSong at 2007-10-28 > top of Msdn China Tech,Java,J2EE,EJB,JMS...
# 3
ejbCreate()必须返回一个实体BEAN主键类型
lip009-深蓝忧郁 at 2007-10-28 > top of Msdn China Tech,Java,J2EE,EJB,JMS...
# 4
主键问题
zblaoshu1979-周博 at 2007-10-28 > top of Msdn China Tech,Java,J2EE,EJB,JMS...
# 5
我已经加了主键啊!!我的Bean中包含ejbCreate方法,如下:
public bankaccount.ejb.AccountPK ejbCreate(
String accountID,
String ownerName) throws javax.ejb.CreateException {
// TODO Auto-generated method stub

PreparedStatement pstmt = null;
Connection conn = null;
DBHelper dbhelper = new DBHelper();

try {
System.out.println("ejbCreate() called.");
this.accountID = accountID;
this.ownerName = ownerName;
this.balance = 0;

conn = dbhelper.getConnection();

pstmt = conn
.prepareStatement("insert into accounts (id,ownerName,balance) values(?,?,?)");
pstmt.setString(1, accountID);
pstmt.setString(2, ownerName);
pstmt.setDouble(3, balance);
pstmt.executeUpdate();

return new AccountPK(accountID);
} catch (Exception e) {
throw new CreateException(e.toString());
} finally {
try {
if (pstmt != null)
pstmt.close();
} catch (Exception e) {
}
try {
if (conn != null)
conn.close();
} catch (Exception e) {
}
}

}
而且ejbFindByPrimaryKey方法也定义了:
public bankaccount.ejb.AccountPK ejbFindByPrimaryPK(
bankaccount.ejb.AccountPK key) throws javax.ejb.FinderException {
// TODO Auto-generated method stub
//return null;
PreparedStatement pstmt = null;
Connection conn = null;
DBHelper dbhelper = new DBHelper();

try{
System.out.println("ejbFindByPrimaryPK("+key+") called.");

conn = dbhelper.getConnection();

pstmt = conn.prepareStatement("select id from accounts where id=?");
pstmt.setString(1,key.toString());
ResultSet rs = pstmt.executeQuery();
rs.next();

return key;
}catch(Exception e){
throw new FinderException(e.toString());
}finally{
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) {}
try { if (conn != null) conn.close(); }
catch (Exception e) {}
}
}
AccountPK是这样定义的:
public class AccountPK implements Serializable {

public String accountID;

public AccountPK(String id){
this.accountID = id;
}

public AccountPK(){

}

public String toString(){
return accountID;
}

public int hashCode(){
return accountID.hashCode();
}

public boolean equals(Object account){
if(!(account instanceof AccountPK)){
return false;
}
return ((AccountPK)account).accountID.equals(accountID);
}
}
各位大虾再看看?
yianhuang at 2007-10-28 > top of Msdn China Tech,Java,J2EE,EJB,JMS...
# 6
没有大虾回复吗?今天晚上又写了一遍,还是报这样的错,为什么啊??
yianhuang at 2007-10-28 > top of Msdn China Tech,Java,J2EE,EJB,JMS...
# 7
建议你别学ejb了,有功夫多学学java的基本的东西吧,我给别人面试从来不问ejb的,因为根本就不会用而且如果你的core java和设计模式非常好的话,ejb根本不用学,自动就会了
wmzsl-王明哲 at 2007-10-28 > top of Msdn China Tech,Java,J2EE,EJB,JMS...