部署BMP的问题

jeoky 2003-08-30 12:45:04
部署BMP时总是报错.

Bean : User
Section: 12.2.2
Warning: The class must be defined as public and must not be abstract.
00:27:28,640 WARN [verifier] EJB spec violation:

Bean : User
Section: 12.2.5
Warning: Every entity bean must define the ejbFindByPrimaryKey method.
00:27:28,640 ERROR [MainDeployer] could not create deployment: file:/D:/jboss/server/default/deploy/UserBMP.jar

org.jboss.deployment.DeploymentException: Verification of Enterprise Beans failed, see above for error messages.
at org.jboss.ejb.EJBDeployer.create(EJBDeployer.java:487)
at org.jboss.deployment.MainDeployer.create(MainDeployer.java:784)
...全文
27 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jeoky 2003-08-30
  • 打赏
  • 举报
回复
我已经定义ejbFindByPrimaryKey方法了,还是报错.

package com.jeoky.ejb;

import javax.ejb.*;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;

public class UserBean implements EntityBean {
EntityContext entityContext;
java.lang.String userId;
java.lang.String name;
java.lang.String password;

private Connection con;
private String DBJndi="java:comp/env/jdbc/MySqlDS";

public java.lang.String ejbCreate(java.lang.String userId) throws CreateException {
this.password="123456";
try{
insertUserRow(userId, "", this.password);
}catch(Exception ex){
throw new EJBException(ex.getMessage());
}
this.userId=userId;
this.name="";
return userId;
}

public void ejbPostCreate(java.lang.String userId) throws CreateException {
/**@todo Complete this method*/
}
public void ejbRemove() throws RemoveException {
/**@todo Complete this method*/
}
public void setUserId(java.lang.String userId) {
this.userId = userId;
}
public void setName(java.lang.String name) {
this.name = name;
}
public void setPassword(java.lang.String password) {
this.password = password;
}
public java.lang.String getUserId() {
return userId;
}
public java.lang.String getName() {
return name;
}
public java.lang.String getPassword() {
return password;
}
public java.lang.String ejbFindByPrimaryKey(java.lang.String userId) throws FinderException {
/**@todo Complete this method*/
boolean result;
try{
result=findByPrimaryKey(userId);
}catch(Exception ex){
throw new EJBException(ex.getMessage());
}
if(result){
return userId;
}
else{
throw new ObjectNotFoundException(userId+" not found.");
}
}
//根据传入的pk取得User的记录
private boolean findByPrimaryKey(String pk)
throws SQLException{

String sqlStatement="select user_id from user where user_id=?";
PreparedStatement ps=con.prepareStatement(sqlStatement);
ps.setString(1, pk);

ResultSet rs=ps.executeQuery();
boolean result=rs.next();
ps.close();
return result;
}

public void ejbLoad() {
/**@todo Complete this method*/
}
public void ejbStore() {
/**@todo Complete this method*/
}
public void ejbActivate() {
/**@todo Complete this method*/
}
public void ejbPassivate() {
/**@todo Complete this method*/
}
public void unsetEntityContext() {
this.entityContext = null;
try{
con.close();
}catch(SQLException ex){
throw new EJBException(ex.getMessage());
}
}
public void setEntityContext(EntityContext entityContext) {
this.entityContext = entityContext;
try{
connectToDB();
}catch(Exception ex){
throw new EJBException(ex.getMessage());
}
}

//设定连结资料库
private void connectToDB() throws NamingException, SQLException {

InitialContext ictx=new InitialContext();
DataSource ds=(DataSource)ictx.lookup(DBJndi);
con=ds.getConnection();
}
//新增一笔User资料
private void insertUserRow(
String user_id, String name, String password)
throws SQLException{

String sqlStatement="insert into user values(? , ? , ?)";

PreparedStatement ps=con.prepareStatement(sqlStatement);

ps.setString(1, user_id);
ps.setString(2, name);
ps.setString(3, password);

ps.executeUpdate();
ps.close();
}
}
wangwd 2003-08-30
  • 打赏
  • 举报
回复
实体Bean必须声明为public,这是为了容器生成bean的实例,
第二,实体bean与会话bean的区别是比较明显的,它必须有一个ejbFindByPrimaryKey方法,这是用来查找表的主键,实体bean必须根据这些主键进行相关的操作
ll42002 2003-08-30
  • 打赏
  • 举报
回复
警告说你的bean中没有ejbFindByPrimaryKey 这个方法??
加上就可以了!
首页 作者序 第一部分 介绍 第1章总括 一.分布式得多层应用程序 二.J2EE容器 三.打包J2EE组件 四.开发者角色 五.本书所用的软件 第2章动手做一个EJB 一.准备工作 二.创建J2EE应用程序 三.创建企业Bean 四.创建J2EE应用程序客户端 五.创建Web客户端 六.设置企业Bean的JNDI名 七.部署J2EE应用程序 八.运行J2EE应用程序客户端 九.运行Web客户端 十.修改J2EE应用程序 十一常见问题和解决方法 第二部分 EJB技术 第3章 企业Bean 一、企业Bean概述 二、会话Bean 三、EntityBean 四、Message-Driven Bean 五、定义客户端访问接口 六、企业Bean的“内容” 七、企业Bean的命名约定 八、企业Bean的生存周期 第4章 有状态会话Bean示例 一.购物车会话Bean CartEJB 二.其他的企业Bean特性 第5章 BMP的例子 一.SavingsAccountEJB 二.用deploytool部署BMP实现的实体Bean 三.为BMP映射表间关系 四.BMP的主键 五.异常处理 第6章 CMP的例子 一、RosterApp应用概述 二、layerEJB代码分析 三、RosterApp配置说明 四、RosterApp中的方法调用 五、运行RosterApp应用程序 六、用deploytool工具部署CMP实现的实体Bean 七、CMP的主键 第7章 一个消息驱动Bean的例子 一.例子应用程序介绍 二.J2EE应用程序客户端 三.消息驱动Bean类 四.运行本例子 五.用deploytool部署消息驱动Bean 六.用deploytool配置JMS客户端 第8章 EJB查询语言 一.术语 二.简单语法 三.查询例子 四.全部语法 五.EJB QL的限制 第三部分 Web技术 第9章 网络客户端及组件 第10章 Java Servlet技术 第11章 JSP技术 第12章 JSP页面中的JavaBean组件 第13章 在JSP页面中自定义标签 第14章 事务 一.什么是事务 二.容器管理事务 三.Bean管理事务 四.企业Bean事务摘要 五.事务超时 六.隔离级别 七.更新多个数据库 八.Web 组件事务 第15章 安全 一.纵览 二.安全角色 三.Web层安全 四.EJB层安全 五.应用程序客户端层安全 六.EIS(Enterprise Information System)层安全 七.传递安全身份 八.J2EE用户、域和组 九.安装服务器证书 第16章 资源连接 一.JNDI名和资源引用 二.数据库连接 三.邮件服务连接 四.URL资源连接

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧