这人气好,一个cmp问题,请帮忙,只剩70分了!
一对多的关系,两张表如下:
create table teacher(
teaID int not null primary key,
teaName varchar(20)
)
create table teacherInfo (
infoID int not null primary key,
teaID int not null,
infoDesc varchar(20)
constraint teaID_FK foreign key(teaID) references teacher(teaID)
)
以下代码全部在 jbuilder8和weblogic7中生成并运行:
(cmp)TeacherBean中:
public java.lang.Integer ejbCreate(Integer teaID, String teaName) throws CreateException {
setTeaID(teaID);
setTeaName(teaName);
return null;
}
public void ejbPostCreate(Integer teaID, String teaName) throws CreateException {
}
(cmp)TeacherInfoBean中:
public java.lang.Integer ejbCreate(Integer infoID,Integer teaID, String infoDesc) throws CreateException {
setInfoID(infoID);
setInfoDesc(infoDesc);
return null;
}
public void ejbPostCreate(Integer infoID,Integer teaID, String infoDesc) throws CreateException {
setTeaID(teaID);
}
sessonBean中调用上面的个cmp :
public void addTeacher(Integer teaID,String teaName,Integer infoID,String infoDesc) {
try {
Context ctx = new InitialContext();
TeacherHome teacherHome = (TeacherHome)ctx.lookup("Teacher");
TeacherInfoHome teacherInfoHome = (TeacherInfoHome)ctx.lookup("TeacherInfo");
Teacher teacher = teacherHome.create(teaID,teaName);
TeacherInfo teacherInfo = teacherInfoHome.create(infoID,teaID,infoDesc);
teacherInfo.setTeacher(teacher);
}catch(Exception e){
e.printStackTrace();
}
}
报错为:
javax.ejb.TransactionRolledbackLocalException: EJB Exception:; nested exception
is: javax.ejb.EJBException: When a cmp-field and a cmr-field (relationship) are
mapped to the same column, the setXXX method for the cmp-field may not be called
. The cmp-field is read-only.
应该怎么解呢????请指点,谢谢!!!!马上送分!!!