0 Replies Latest reply on Feb 24, 2005 4:27 AM by Zoharqain Kazmi

    EJB-ql with relationship

    Zoharqain Kazmi Newbie

      Hi,
      I have just created two cmp entity beans i.e. user master and user marks in which there is a many to one relation ship between the usermarks and usermaster. I have a method (implemented with ejb-ql) findAll in both beans. I m getting eeception
      14:45:17,816 INFO [STDOUT] java.sql.SQLException: ORA-00904: "TEMPUSERMASTER":
      invalid identifier

      while executing find All method for child table 'Usermarks'. Can u tell me how can i solve this problem, i m attaching here all three xml

      ejb-jar.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
      <ejb-jar>
      <display-name>EJBModule1</display-name>
      <enterprise-beans>

      <display-name>JbossSess</display-name>
      <ejb-name>JbossSess</ejb-name>
      sessionBeans.JbossSessHome
      sessionBeans.JbossSess
      <ejb-class>sessionBeans.JbossSessBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>


      <display-name>TempUserMaster</display-name>
      <ejb-name>TempUserMaster</ejb-name>
      <local-home>entityBeans.TempUserMasterHome</local-home>
      entityBeans.TempUserMaster
      <ejb-class>entityBeans.TempUserMasterBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.math.BigDecimal</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>TempUserMaster</abstract-schema-name>
      <cmp-field>
      <field-name>loginname</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>password</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>userMasterPk</field-name>
      </cmp-field>
      <primkey-field>userMasterPk</primkey-field>

      <query-method>
      <method-name>findAll</method-name>
      <method-params />
      </query-method>
      <ejb-ql>Select OBJECT(o) from TempUserMaster AS o</ejb-ql>



      <display-name>TempUserMarks</display-name>
      <ejb-name>TempUserMarks</ejb-name>
      <local-home>entityBeans.TempUserMarksHome</local-home>
      entityBeans.TempUserMarks
      <ejb-class>entityBeans.TempUserMarksBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.math.BigDecimal</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>TempUserMarks</abstract-schema-name>
      <cmp-field>
      <field-name>mark</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>subject</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>userMarkPk</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>userMasterPkFk</field-name>
      </cmp-field>
      <primkey-field>userMarkPk</primkey-field>

      <query-method>
      <method-name>findAll</method-name>
      <method-params />
      </query-method>
      <ejb-ql>Select OBJECT(o) from TempUserMarks AS o</ejb-ql>


      </enterprise-beans>

      <ejb-relation>
      <ejb-relation-name>tempUserMarks-tempUserMaster</ejb-relation-name>
      <ejb-relationship-role>
      tempUserMarks
      <ejb-relationship-role-name>TempUserMarksRelationshipRole</ejb-relationship-role-name>
      Many
      <relationship-role-source>
      tempUserMarks
      <ejb-name>TempUserMarks</ejb-name>
      </relationship-role-source>
      <cmr-field>
      tempUserMaster
      <cmr-field-name>tempUserMaster</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      tempUserMaster
      <ejb-relationship-role-name>TempUserMasterRelationshipRole</ejb-relationship-role-name>
      One
      <relationship-role-source>
      tempUserMaster
      <ejb-name>TempUserMaster</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      </ejb-relation>

      <assembly-descriptor>
      <container-transaction>

      <ejb-name>JbossSess</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>

      <ejb-name>TempUserMaster</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>

      <ejb-name>TempUserMarks</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      </assembly-descriptor>
      </ejb-jar>

      jboss.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.2//EN" "http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd">

      <enterprise-beans>

      <ejb-name>JbossSess</ejb-name>
      <jndi-name>sessionBeans/JbossSess</jndi-name>
      <local-jndi-name>JbossSess</local-jndi-name>


      <ejb-name>TempUserMaster</ejb-name>
      <local-jndi-name>TempUserMaster</local-jndi-name>


      <ejb-name>TempUserMarks</ejb-name>
      <local-jndi-name>TempUserMarks</local-jndi-name>

      </enterprise-beans>


      jbosscmp-jdbc.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 3.2//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_2.dtd">
      <jbosscmp-jdbc>

      java:/OracleDS
      <datasource-mapping>Oracle9i</datasource-mapping>

      <enterprise-beans>

      <ejb-name>TempUserMaster</ejb-name>
      <table-name>TEMP_USER_MASTER</table-name>
      <cmp-field>
      <field-name>loginname</field-name>
      <column-name>LOGINNAME</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>password</field-name>
      <column-name>PASSWORD</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>userMasterPk</field-name>
      <column-name>USER_MASTER_PK</column-name>
      </cmp-field>


      <ejb-name>TempUserMarks</ejb-name>
      <table-name>TEMP_USER_MARKS</table-name>
      <cmp-field>
      <field-name>mark</field-name>
      <column-name>MARK</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>subject</field-name>
      <column-name>SUBJECT</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>userMarkPk</field-name>
      <column-name>USER_MARK_PK</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>userMasterPkFk</field-name>
      <column-name>USER_MASTER_PK_FK</column-name>
      </cmp-field>

      </enterprise-beans>
      </jbosscmp-jdbc>

      And classes for child table are
      home

      package entityBeans;

      import javax.ejb.EJBLocalHome;
      import java.math.BigDecimal;
      import javax.ejb.CreateException;
      import javax.ejb.FinderException;
      import java.util.Collection;

      public interface TempUserMarksHome
      extends EJBLocalHome {

      public TempUserMarks create(BigDecimal userMarkPk) throws CreateException;

      public TempUserMarks findByPrimaryKey(BigDecimal userMarkPk) throws
      FinderException;

      public Collection findAll() throws FinderException;
      }

      Bean

      package entityBeans;

      import javax.ejb.EntityBean;
      import javax.ejb.EntityContext;
      import java.math.BigDecimal;
      import javax.ejb.CreateException;
      import javax.ejb.RemoveException;
      import java.util.Collection;
      import javax.ejb.FinderException;

      public abstract class TempUserMarksBean
      implements EntityBean {
      EntityContext entityContext;

      public BigDecimal ejbCreate(BigDecimal userMarkPk) throws CreateException {
      setUserMarkPk(userMarkPk);
      return null;
      }

      public void ejbPostCreate(BigDecimal userMarkPk) throws CreateException {
      }

      public void ejbRemove() throws RemoveException {
      }

      public abstract void setMark(BigDecimal mark);

      public abstract void setSubject(String subject);

      public abstract void setUserMarkPk(BigDecimal userMarkPk);

      public abstract void setUserMasterPkFk(BigDecimal userMasterPkFk);

      abstract public void setTempUserMaster(TempUserMaster tempUserMaster);

      public abstract BigDecimal getMark();

      public abstract String getSubject();

      public abstract BigDecimal getUserMarkPk();

      public abstract BigDecimal getUserMasterPkFk();

      abstract public TempUserMaster getTempUserMaster();

      public void ejbLoad() {
      }

      public void ejbStore() {
      }

      public void ejbActivate() {
      }

      public void ejbPassivate() {
      }

      public void setEntityContext(EntityContext entityContext) {
      this.entityContext = entityContext;
      }

      public void unsetEntityContext() {
      this.entityContext = null;
      }

      }

      local

      package entityBeans;

      import javax.ejb.EJBLocalObject;
      import java.math.BigDecimal;
      import java.util.Collection;

      public interface TempUserMarks
      extends EJBLocalObject {

      public void setTempUserMaster(TempUserMaster tempUserMaster);

      public TempUserMaster getTempUserMaster();

      public void setMark(BigDecimal mark);

      public BigDecimal getMark();

      public void setSubject(String subject);

      public String getSubject();

      public BigDecimal getUserMarkPk();

      public void setUserMasterPkFk(BigDecimal userMasterPkFk);

      public BigDecimal getUserMasterPkFk();

      }

      Thanx in advance.