配置文件片段如下
<entity>
      <display-name>AccountBean</display-name>
      <ejb-name>AccountBean</ejb-name>
      <home>com.AccountHome</home>
      <remote>com.AccountRemote</remote>
      <ejb-class>com.AccountBean</ejb-class>
      <persistence-type>Bean</persistence-type>
      <prim-key-class>com.AccountBeanPK</prim-key-class>
      <reentrant>False</reentrant>
      <cmp-version>2.x</cmp-version>
    </entity>

解决方案 »

  1.   

    只要增加 ejbLoad() 就可以实现
    public void ejbLoad() throws EJBException, RemoteException {
            System.out.println("ejbLoad() called!");
            AccountBeanPK pk = (AccountBeanPK)this.context.getPrimaryKey();
            String id = pk.id;
            System.out.println("id===================" + id);
            try {
                ....
                if (rs.next()) {
                    this.field= rs.getString(1);
                }            ps.close();
            } catch (SQLException e) {
                e.printStackTrace();
                throw new EJBException(e.getMessage());
            }
        }