1 Reply Latest reply on Sep 22, 2004 9:33 AM by Pablo Javier Santa Cruz Cosp

    UnknownPathException: don't know how to do EJB-QL queries

    Pablo Javier Santa Cruz Cosp Newbie

      Dear fellow,

      I have been trying without success to perform a simple (at least, I think so) EJB-QL query to retrieve all users belonging to a business partner.

      Here is my scenario:

      -> PostgreSQL 7.3.2 (RedHat Linux 8.0)
      -> JBOSS 3.2.5 (Java 2 SDK 1.4.2_05/RedHat Linux 9.0)
      -> CMP 2.0

      As I said, I have two EJBs:

      1) UserEJB (UserEJB shcema)
      2) BusinessPartnerEJB (BusinessPartnerEJB schema)

      UserEJB has a finder named findByBusinessPartnerId which keeps throwing a UnknownPathException, stating that EJB-QL sentence failed:

      -----

      xdoclet tags that generates finder:

      * @ejb.finder
      * description = "query to retrieve all users from a business partner"
      * unchecked = "true"
      * signature="java.util.Collection findByBusinessPartnerId(java.lang.Integer businessPartnerId)"
      * query="SELECT OBJECT(o) FROM UserEJB AS o WHERE o.businessPartner.businessPartnerId=?1"

      exception thrown when deployed:

      Error compiling EJB-QL statement 'SELECT OBJECT(o) FROM UserEJB AS o WHERE o.businessPartner.businessPartnerId=?1'; - nested throwable: (org.jboss.ejb.plugins.cmp.ejbql.UnknownPathException: In path field is not a cmr field: at line 1, column 59. Encountered: "businessPartner" after: "o.")

      ------

      Here is full source code list of UserEJB.java:

      package py.com.roshka.wops4.common.user.ejb;

      import java.rmi.RemoteException;
      import java.util.Collection;

      import javax.ejb.CreateException;
      import javax.ejb.EJBException;
      import javax.ejb.EntityBean;
      import javax.ejb.EntityContext;
      import javax.ejb.FinderException;
      import javax.ejb.RemoveException;
      import javax.naming.NamingException;

      import py.com.roshka.wops4.common.businessPartner.interfaces.BusinessPartnerEJBLocal;
      import py.com.roshka.wops4.common.businessPartner.interfaces.BusinessPartnerEJBLocalHome;
      import py.com.roshka.wops4.common.businessPartner.util.BusinessPartnerEJBUtil;
      import py.com.roshka.wops4.common.user.data.UserEJBData;

      /**
      * @author PABLO JAVIER
      *
      * @ejb.bean description="User"
      * display-name="User EJB"
      * name="UserEJB"
      * primkey-field="userName"
      * schema="UserEJB"
      * type="CMP"
      * cmp-version = "2.x"
      * view-type="local"
      *
      * @ejb.facade
      * view-type = "remote"
      *
      * @ejb.util generate = "physical"
      *
      * @ejb.persistence table-name = "wops4_users"
      *
      * @ejb.value-object
      * name = "User"
      * match = "*"
      *
      * @ejb.finder
      * signature="java.util.Collection findAll()"
      * query="SELECT OBJECT(o) FROM UserEJB o"
      *
      * @ejb.finder
      * description = "query to authenticate and get user data"
      * unchecked = "true"
      * signature="py.com.roshka.wops4.common.user.interfaces.UserEJBLocal findByUserNameAndPassword(java.lang.String userName, java.lang.String password)"
      * query="SELECT OBJECT(o) FROM UserEJB o where o.userName=?1 AND o.password=?2"
      *
      * @ejb.finder
      * description = "query to retrieve all users from a business partner"
      * unchecked = "true"
      * signature="java.util.Collection findByBusinessPartnerId(java.lang.Integer businessPartnerId)"
      * query="SELECT OBJECT(o) FROM UserEJB AS o WHERE o.businessPartner.businessPartnerId=?1"
      *
      */

      public abstract class UserEJB implements EntityBean {

      /**
      * @ejb.persistence
      * jdbc-type="VARCHAR"
      * sql-type="varchar(20)"
      *
      */
      public abstract String getUserName();
      public abstract void setUserName(String userName);

      /**
      * @ejb.persistence
      * jdbc-type="VARCHAR"
      * sql-type = "varchar(20)"
      */
      public abstract String getPassword();
      /**
      * @ejb.interface-method
      */
      public abstract void setPassword(String password);

      /**
      * @ejb.persistence
      */
      public abstract Boolean getEnabled();
      public abstract void setEnabled(Boolean enabled);

      /**
      * @ejb.persistence
      * jdbc-type="VARCHAR"
      * sql-type = "varchar(40)"
      */
      public abstract String getFirstName();
      public abstract void setFirstName(String firstName);

      /**
      * @ejb.persistence
      * jdbc-type="VARCHAR"
      * sql-type = "varchar(40)"
      */
      public abstract String getLastName();
      public abstract void setLastName(String lastName);

      /**
      * @ejb.persistence
      * jdbc-type="VARCHAR"
      * sql-type = "varchar(80)"
      */
      public abstract String getEmail();
      public abstract void setEmail(String email);

      /**
      * @ejb.persistence
      * jdbc-type="VARCHAR"
      * sql-type = "varchar(80)"
      * @return
      */
      public abstract String getAltEmail();
      public abstract void setAltEmail(String altEmail);

      /**
      * @ejb.persistence
      * jdbc-type="VARCHAR"
      * sql-type = "varchar(20)"
      */
      public abstract String getPhone1();
      public abstract void setPhone1(String phone1);

      /**
      * @ejb.persistence
      * jdbc-type="VARCHAR"
      * sql-type = "varchar(20)"
      */
      public abstract String getPhone2();
      public abstract void setPhone2(String phone2);

      /**
      * @ejb.persistence
      * jdbc-type="VARCHAR"
      * sql-type = "varchar(20)"
      */
      public abstract String getMobile();
      public abstract void setMobile(String mobile);

      /**
      * @ejb.persistence
      * jdbc-type="CLOB"
      * sql-type = "text"
      */
      public abstract String getAdditionalInfo();
      public abstract void setAdditionalInfo(String additionalInfo);

      /**
      * @ejb.persistence
      * jdbc-type="NUMERIC"
      * sql-type="NUMERIC(1)"
      */
      public abstract Integer getSex();
      public abstract void setSex(Integer sex);

      // Relations

      /**
      * @ejb.value-object aggregate="py.com.roshka.wops4.common.businessPartner.data.BusinessPartnerEJBData"
      * aggregate-name="BusinessPartner"
      * relation="external"
      *
      * @ejb.relation
      * name = "User-belongs-to-BusinessPartner"
      * role-name = "User-BusinessPartner"
      * target-ejb = "BusinessPartnerEJB"
      * target-role-name = "BusinessPartner-has-Users"
      * target-multiple = "yes"
      *
      *
      * @jboss.relation
      * fk-constraint = "true"
      * fk-column = "businessPartnerId"
      * related-pk-field = "businessPartnerId"
      *
      * @ejb.persistence
      * column-name = "businessPartnerId"
      * jdbc-type = "INTEGER"
      * sql-type = "integer"
      *
      * @return
      */
      public abstract BusinessPartnerEJBLocal getBusinessPartner();
      public abstract void setBusinessPartner(BusinessPartnerEJBLocal cliente);

      /**
      * @ejb.relation
      * name = "User-have-Roles"
      * role-name = "User-Role"
      *
      * @jboss.relation
      * fk-column = "roleName"
      * fk-constraint = "true"
      * related-pk-field = "roleName"
      *
      * @jboss.relation-table table-name = "wops4_users_by_role"
      *
      * @ejb.value-object aggregate="py.com.roshka.wops4.common.role.data.RoleEJBData"
      * aggregate-name="Roles"
      * members="py.com.roshka.wops4.common.role.interfaces.RoleEJBLocal"
      * members-name="py.com.roshka.wops4.common.role.ejb.RoleEJB"
      * relation="external"
      * type="java.util.Collection"
      * @return
      */
      public abstract Collection getRoles();
      public abstract void setRoles(Collection roles);



      /**
      * @ejb.interface-method
      * @ejb.facade-method
      */
      public void setData(UserEJBData user)
      throws FinderException, NamingException {
      setFields(user);
      setRelations(user);
      }
      /**
      * @param user
      */
      private void setRelations(UserEJBData user)
      throws FinderException, NamingException {
      if (user.getBusinessPartner() != null){

      BusinessPartnerEJBLocalHome businessPartnerHome = BusinessPartnerEJBUtil.getLocalHome();
      BusinessPartnerEJBLocal businessPartner = businessPartnerHome.findByPrimaryKey(user.getBusinessPartner().getPrimaryKey());
      setBusinessPartner(businessPartner);
      }
      }
      /**
      * @param user
      */
      private void setFields(UserEJBData user) {
      setFirstName(user.getFirstName());
      setLastName(user.getLastName());
      setPassword(user.getPassword());
      setSex(user.getSex());

      setPhone1(user.getPhone1());
      setPhone2(user.getPhone2());
      setMobile(user.getMobile());

      setEmail(user.getEmail());
      setAltEmail(user.getAltEmail());
      setEnabled(user.getEnabled());

      setAdditionalInfo(user.getAdditionalInfo());
      }

      /**
      * @ejb.interface-method
      * @ejb.permission unchecked = "true"
      * @ejb.facade-method
      * @return
      */
      public UserEJBData getData() {
      UserEJBData user = new UserEJBData();

      user.setUserName(getUserName());
      user.setFirstName(getFirstName());
      user.setLastName(getLastName());
      user.setPassword(getPassword());
      user.setSex(getSex());

      user.setPhone1(getPhone1());
      user.setPhone2(getPhone2());
      user.setMobile(getMobile());

      user.setEmail(getEmail());
      user.setAltEmail(getAltEmail());
      user.setEnabled(getEnabled());

      user.setAdditionalInfo(getAdditionalInfo());

      // roles relationship

      //user.setRoless(getRoles().toArray());

      return user;
      }



      /**
      *
      */
      public UserEJB() {
      super();
      }

      /**
      * @ejb.create-method
      */
      public String ejbCreate(UserEJBData user)
      throws CreateException {
      setUserName(user.getUserName());
      setFields(user);
      return null;
      }

      public void ejbPostCreate(UserEJBData user)
      throws CreateException {
      try {
      setRelations(user);
      } catch (FinderException e) {
      throw new CreateException("Cannot create: " + e.getLocalizedMessage());
      } catch (NamingException e) {
      throw new CreateException("Cannot create: " + e.getLocalizedMessage());
      }
      }

      public void ejbActivate() throws EJBException, RemoteException {}
      public void ejbLoad() throws EJBException, RemoteException {}
      public void ejbPassivate() throws EJBException, RemoteException {}
      public void ejbRemove()
      throws RemoveException, EJBException, RemoteException {}
      public void ejbStore() throws EJBException, RemoteException {}
      public void setEntityContext(EntityContext arg0)
      throws EJBException, RemoteException {}
      public void unsetEntityContext() throws EJBException, RemoteException {}

      }

      ----

      Am I doing something wrong?

      Thanks in advace.