我建议的方式是:你的这个不要写在ejbCreate()中,最好还是放到sessionBean中,然后调用你自己的一个自增bean
解决方案 »
- 数据库中主键和业务无关怎么处理?是否要放到javaBean中
- Java 弹出消息提示后(没有按钮),让程序内所有县城处于等待状态
- tomacat 服务器 配置问题
- 关于jsp页面间数据参数的传递问题
- 在jboss下部署2个war包,会产生静态变量相同的结果,怎么办?
- 高手,好心人一定要帮帮手啊
- 安装websphere5.1停滞不动了??(SOS)
- 一个关于数据格式化显示的问题
- J2EE服务器启动时会创建Entity Bean实例并把它们放入池中,J2EE服务器根据那个配置文件来决定实例的个数?
- spring cloud 启动报错
- 哪位好心人可以帮帮我?哪里有jbuilder9的入门教程下载呀?我找了好久找不到
- 怎么在JSP里做使显示的数据表导出EXCEL
如果用Session Bean ,是否是用Stateful。
还有,我的JBoss服务器会出现这个问题。 请问其他服务器也有这个问题吗?
听说 hibernate实现O-R映射不会出现此问题!
session bean 中
public Integer insertRecord(MaterialInfo material,AdditionalInfo additional,
ArrayList appends,SourceInfo source){
// here we will insert the data to database:infodb
// It's may need the operation of transaction,however,we should
// deal with it later in the form of mature product.
if (additional != null) {
//insert the record of additional.
//we must first declare the necessary parameters to be put into ejbCreate.
try {
qBTb_Additional = qBTb_AdditionalHome.create(additional.
getAcqPerson(),
additional.getIndexLevel(), additional.getStatus());
} catch (Exception e) {
e.printStackTrace();
}
qBTb_Additional.setAcquirePersonAdv(additional.getAcqPersonAdv());
qBTb_Additional.setCheckAdv(additional.getCheckAdv());
qBTb_Additional.setCheckPerson(additional.getCheckPerson());
qBTb_Additional.setCheckTime(additional.getCheckTime());
qBTb_Additional.setMark(additional.getMark());
qBTb_Additional.setReferenceAccount(additional.
getReferenceAccount());
qBTb_Additional.setSubCheckTime(additional.getSubCheckTime()); }
entity bean 中
public Integer ejbCreate(String acqPerson,String indexLevel,String status){
Integer id=null;
try{
this.setAcquirePerson(acqPerson);
this.setIndexLevel(indexLevel);
this.setStatus(status); Context context = new InitialContext();
SequenceSessionInfoLocalHome ahome=(SequenceSessionInfoLocalHome)
context.lookup("SequenceSessionInfoLocal"); SequenceSessionInfoLocal aSequence=ahome.create();
//accept next key
id=new Integer(aSequence.getNextNumberInSequence("QBTbAdditional"));
this.setAdditionalID(id); }catch(Exception o){o.printStackTrace();} return id;
}//ejbCreate
至于自增bean如何写,请参考一下J2EE 设计模式等书籍。后边是附带代码的。