用一个包装类做为主键.在ejbCreate时,用两个字段的值生成包装类.
ejbActivate时,通过EntityContext.getPrimaryKey()来得到该包装类,从中得到两个字段的值,根据这两个字段的值从数据库中查找记录!

解决方案 »

  1.   

    实现了序列化的JAVA BEAN类,类中包括主键字段就可以了。
    用的时候要在配置文件中配置该类。
      

  2.   

    正好手头有一个刚写的例子
    //出自精通EJB第三版/**
     * Created by IntelliJ IDEA.
     * User: Administrator
     * Date: 2005-4-23
     * Time: 15:03:53
     * To change this template use File | Settings | File Templates.
     */
    public class AccountPK implements java.io.Serializable{
        public String accountID;    public AccountPK() {
        }    public AccountPK(String accountID) {
            this.accountID=accountID;
        }    public int hashCode(){
            return accountID.hashCode();
        }    public String toString(){
            return "account:"+accountID;
        }    public boolean equals(Object accountPK){
            if(!(accountPK instanceof AccountPK)) return false;
            return (((AccountPK)accountPK).accountID).equals(accountID);
        }
    }
      

  3.   

    两个字段最典型的就是用hashCode()^加了
    比如String s1,s2;//s1,s2是你的字段名
    public int hashCode(){
       return s1.hashCode()^s2.hashCode();
    }