部署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)
...全文
23 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 这个方法??
加上就可以了!

67,512

社区成员

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

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