昨天在修改过去的J2EE项目时,使用cvs检出时把没有提交到cvs中的修改(包括以前写的,没有提交过的程序)删除了。其中CMP中EJB-QL就没有了,于是只有重写了。县总结如下:
CMP中EJB-QL的使用有以下几部分(缺一不可):
1.在Home接口中定义方法:
public java.util.Collection findByFileInfo(Integer MagazineNumber)
throws javax.ejb.FinderException,java.rmi.RemoteException;
2.在Bean中定义abstract get/setXXX方法:
private EntityContext context;
public abstract Integer getMagazineNumber();
public abstract void setMagazineNumber(Integer MagazineNum);
public abstract char getResourseType();
public abstract void setResourseType(char ResT);
public abstract String getMagazineFileName();
public abstract void setMagazineFileName(String MagaFN);
public abstract String getTypeNumber();
public abstract void setTypeNumber(String TypeN);。。。。。
3.与Bean对应在EJB对象中也要定义这些方法,不过要throws java.rmi.RemoteException.
public interface MagazineInfo extends javax.ejb.EJBObject{
public abstract Integer getMagazineNumber() throws java.rmi.RemoteException;
public abstract void setMagazineNumber(Integer MagazineNum)throws java.rmi.RemoteException;
public abstract char getResourseType()throws java.rmi.RemoteException;
public abstract void setResourseType(char ResT)throws java.rmi.RemoteException;
public abstract String getMagazineFileName()throws java.rmi.RemoteException;
public abstract void setMagazineFileName(String MagaFN)throws java.rmi.RemoteException;
public abstract String getTypeNumber()throws java.rmi.RemoteException;
public abstract void setTypeNumber(String TypeN)throws java.rmi.RemoteException;。。。。
4.在ejb-jar.xml中定义cmp中的实体的数据项和EJB-ql语句:
<entity >
<---定义实体接口描述-->
<description><![CDATA[Description for MagazinePossibleInfo]]></description>
<display-name>Name for MagazinePossibleInfo</display-name>
<ejb-name>MagazinePossibleInfo</ejb-name>
<home>bitiDL.managementConsle.magazinePossibleInfoEntity.interfaces.MagazinePossibleInfoHome</home>
<remote>bitiDL.managementConsle.magazinePossibleInfoEntity.interfaces.MagazinePossibleInfo</remote>
<local-home>bitiDL.managementConsle.magazinePossibleInfoEntity.interfaces.MagazinePossibleInfoLocalHome</local-home>
<local>bitiDL.managementConsle.magazinePossibleInfoEntity.interfaces.MagazinePossibleInfoLocal</local>
<ejb-class>bitiDL.managementConsle.magazinePossibleInfoEntity.ejb.MagazinePossibleInfoCMP</ejb-class>
<--定义为CMP--->
<persistence-type>Container</persistence-type>
<--定义容器主健-->
<prim-key-class>java.lang.Integer</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<--定义在数据库中对应的表名--->
<abstract-schema-name>MagazinePossibleInfo</abstract-schema-name>
<--定义各个描述数据项,注意首字母小写,可与大写兼容同义-->
<cmp-field>
<field-name>magazineNumber</field-name>
</cmp-field>
<cmp-field>
<field-name>author</field-name>
</cmp-field>
<cmp-field>
<field-name>authorDepartment</field-name>
</cmp-field>
<cmp-field>
<field-name>authordegree</field-name>
</cmp-field>
<cmp-field>
<field-name>speciality</field-name>
</cmp-field>
<cmp-field>
<field-name>retationInfo</field-name>
</cmp-field>
<cmp-field>
<field-name>publishment</field-name>
</cmp-field>
<cmp-field>
<field-name>otherLanguageSummary</field-name>
</cmp-field>
<--定义主健-->
<primkey-field>magazineNumber</primkey-field>
<!-- Write a file named ejb-finders-MagazinePossibleInfoBean.xml if you want to define extra finders. -->
<--EJB中方法描述-->
<query>
<query-method>
<method-name>findByPossibleInfo</method-name>
<method-params>
<method-param>java.lang.Integer</method-param>
</method-params>
</query-method>
<--EJB-QL语句,可以返回对象,也可以是单个数据项-->
<ejb-ql>
<![CDATA[SELECT OBJECT(h) FROM MagazinePossibleInfo AS h WHERE h.magazineNumber = ?1]]> //其中的数字标示是参数的次序,从1开始。
</ejb-ql>
</query>
</entity>