3 Replies Latest reply on Nov 14, 2001 7:29 PM by Allen Fogleson

    EJB-QL Problem

    Allen Fogleson Newbie

      I know others have said they have EJB-QL working in EJB-QL however I have experienced problems with it. Now maybe I am just missing something so I thought I would post my appropriate files here and see if anyone else can figure out what I am doing wrong.

      here is a portion of the Bean class:

      package com.darklite.ejb.entity;

      import java.rmi.*;
      import javax.ejb.*;
      import java.math.*;
      import com.darklite.ejb.entity.*;
      import com.darklite.DemographicDO;

      public abstract class UsersBean implements EntityBean {
      EntityContext entityContext;

      public abstract BigDecimal getUser_pk();
      public abstract String getUsername();
      public abstract String getPassword();
      public abstract String getEmail();
      public abstract String getFirstname();
      public abstract String getLastname();
      public abstract String getCode();
      public abstract String getActive();
      public abstract DemographicsLocal getDemographics();

      and here is my beanHome

      package com.darklite.ejb.entity;

      import java.rmi.*;
      import javax.ejb.*;
      import java.util.Collection;
      import java.math.*;
      import com.darklite.ejb.entity.Users;
      import com.darklite.DemographicDO;

      public interface UsersHome extends EJBHome {
      public Users create(BigDecimal userPk, String username, String password, String email, String firstname, String lastname, String code, String active, DemographicDO demographics) throws CreateException, RemoteException;
      public Users create(BigDecimal userPk, String username, String password, String email, String firstname, String lastname, String code, String active) throws CreateException, RemoteException;
      public Users create(BigDecimal userPk) throws RemoteException, CreateException;
      public Users findByPrimaryKey(BigDecimal primaryKey) throws RemoteException, FinderException;
      public Collection findAll() throws RemoteException, FinderException;
      public Users findByName(String username) throws RemoteException, FinderException;
      }

      So I need to implement a findByName method in ejb-ql. Here is the DD for it:

      <!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>
      <enterprise-beans>

      <ejb-name>Demographics</ejb-name>
      com.darklite.ejb.entity.DemographicsHome
      <local-home>com.darklite.ejb.entity.DemographicsLocalHome</local-home>
      com.darklite.ejb.entity.DemographicsLocal
      com.darklite.ejb.entity.Demographics
      <ejb-class>com.darklite.ejb.entity.DemographicsBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.String</prim-key-class>
      false
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>demographics</abstract-schema-name>
      <cmp-field><field-name>username</field-name></cmp-field>
      <cmp-field><field-name>companyname</field-name></cmp-field>
      <cmp-field><field-name>street1</field-name></cmp-field>
      <cmp-field><field-name>street2</field-name></cmp-field>
      <cmp-field><field-name>state</field-name></cmp-field>
      <cmp-field><field-name>city</field-name></cmp-field>
      <cmp-field><field-name>country</field-name></cmp-field>
      <cmp-field><field-name>postalcode</field-name></cmp-field>
      <cmp-field><field-name>sex</field-name></cmp-field>
      <cmp-field><field-name>age</field-name></cmp-field>
      <cmp-field><field-name>jobfunction</field-name></cmp-field>
      <primkey-field>username</primkey-field>


      <ejb-name>Users</ejb-name>
      com.darklite.ejb.entity.UsersHome
      <local-home>com.darklite.ejb.entity.UsersLocalHome</local-home>
      com.darklite.ejb.entity.UsersLocal
      com.darklite.ejb.entity.Users
      <ejb-class>com.darklite.ejb.entity.UsersBean</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>users</abstract-schema-name>
      <cmp-field><field-name>user_pk</field-name></cmp-field>
      <cmp-field><field-name>username</field-name></cmp-field>
      <cmp-field><field-name>password</field-name></cmp-field>
      <cmp-field><field-name>email</field-name></cmp-field>
      <cmp-field><field-name>firstname</field-name></cmp-field>
      <cmp-field><field-name>lastname</field-name></cmp-field>
      <cmp-field><field-name>code</field-name></cmp-field>
      <cmp-field><field-name>active</field-name></cmp-field>
      <cmr-field><cmr-field-name>demographics</cmr-field-name></cmr-field>
      <primkey-field>user_pk</primkey-field>

      <query-method>
      <method-name>findByName</method-name>
      <method-params>
      <method-param>java.lang.String</method-param>
      </method-params>
      </query-method>
      <ejb-ql>SELECT OBJECT(u) FROM users u where u.username=?1</ejb-ql>


      </enterprise-beans>

      <ejb-relation>
      <ejb-relation-name>User-Demographics</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>User-Demographics</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>Users</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>demographics</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Demographics-belongs-to-Users</ejb-relationship-role-name>
      One
      <cascade-delete />
      <relationship-role-source>
      <ejb-name>Demographics</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      </ejb-relation>

      <assembly-descriptor>
      <container-transaction>

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

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

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

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

      if I change the findbyName method to findByUsername and take out the ejb-ql then everything works just like 2.4.3 would... but if I keep the ejb-ql i get the following error on deployment:

      [2001-11-13 15:12:27,990,EntityContainer,DEBUG] Begin java:comp/env for EJB: Users
      [2001-11-13 15:12:27,990,EntityContainer,DEBUG] TCL: java.net.URLClassLoader@11f801
      [2001-11-13 15:12:28,000,EntityContainer,DEBUG] End java:comp/env for EJB: Users
      [2001-11-13 15:12:28,000,BaseLocalContainerInvoker,DEBUG] Bound Local Users to local/Users
      [2001-11-13 15:12:28,000,AutoDeployer,DEBUG] Received notification of mbean J2EE:service=EJB,jndiName=Users's deployment.
      [2001-11-13 15:12:28,000,ServiceController,WARN] J2EE:service=EJB,jndiName=Users does not implement any Service methods
      [2001-11-13 15:12:28,030,JRMPContainerInvoker,DEBUG] JRMP 1.3 CI initialized
      [2001-11-13 15:12:28,040,ConnectionFactoryLoader,DEBUG] ConnectionFactoryLoader.getObjectInstance, name = 'multiDS'
      [2001-11-13 15:12:28,040,ContainerFactory,ERROR] Could not deploy file:/C:/jboss-3.0.0alpha/deploy/Default/multideployer.ear
      java.lang.NullPointerException
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge.loadSelectors(JDBCEntityBridge.java:213)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge.(JDBCEntityBridge.java:90)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.init(JDBCStoreManager.java:117)
      at org.jboss.ejb.plugins.CMPPersistenceManager.init(CMPPersistenceManager.java:141)
      at org.jboss.ejb.EntityContainer.start(EntityContainer.java:369)
      at org.jboss.ejb.Application.start(Application.java:200)
      at org.jboss.ejb.ContainerFactory.deploy(ContainerFactory.java:381)
      at org.jboss.ejb.ContainerFactory.deploy(ContainerFactory.java:307)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1628)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
      at org.jboss.deployment.J2eeDeployer.startModules(J2eeDeployer.java:467)
      at org.jboss.deployment.J2eeDeployer.startApplication(J2eeDeployer.java:444)
      at org.jboss.deployment.J2eeDeployer.deploy(J2eeDeployer.java:215)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1628)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
      at org.jboss.deployment.AutoDeployer.deploy(AutoDeployer.java:654)
      at org.jboss.deployment.AutoDeployer.run(AutoDeployer.java:327)
      at java.lang.Thread.run(Unknown Source)
      [2001-11-13 15:12:28,050,ServiceController,DEBUG] undeploying J2EE:service=EJB,jndiName=Registration from server
      [2001-11-13 15:12:28,050,ServiceController,DEBUG] undeploying J2EE:service=EJB,jndiName=Demographics from server
      [2001-11-13 15:12:28,050,ServiceController,DEBUG] undeploying J2EE:service=EJB,jndiName=userActions from server
      [2001-11-13 15:12:28,050,ServiceController,DEBUG] undeploying J2EE:service=EJB,jndiName=Users from server
      [2001-11-13 15:12:28,050,J2eeDeployer#Default,ERROR] Starting multideployer.ear failed!
      javax.management.MBeanException: Exception thrown in operation deploy
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1644)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
      at org.jboss.deployment.J2eeDeployer.startModules(J2eeDeployer.java:467)
      at org.jboss.deployment.J2eeDeployer.startApplication(J2eeDeployer.java:444)
      at org.jboss.deployment.J2eeDeployer.deploy(J2eeDeployer.java:215)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1628)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
      at org.jboss.deployment.AutoDeployer.deploy(AutoDeployer.java:654)
      at org.jboss.deployment.AutoDeployer.run(AutoDeployer.java:327)
      at java.lang.Thread.run(Unknown Source)
      [2001-11-13 15:12:28,140,J2eeDeployer#Default,INFO] Module multideployer.war is not running
      [2001-11-13 15:12:28,160,J2eeDeployer#Default,INFO] Module multideployer.ear is not running
      [2001-11-13 15:12:28,190,J2eeDeployer#Default,INFO] Destroying application multideployer.ear
      [2001-11-13 15:12:28,320,J2eeDeployer#Default,INFO] Destroyed
      [2001-11-13 15:12:28,320,AutoDeployer,ERROR] Deployment failed:file:/C:/jboss-3.0.0alpha/deploy/multideployer.ear
      org.jboss.deployment.J2eeDeploymentException: Error while starting multideployer.ear: Could not deploy file:/C:/jboss-3.0.0alpha/deploy/Default/multideployer.ear, Cause: org.jboss.ejb.DeploymentException: Could not deploy file:/C:/jboss-3.0.0alpha/deploy/Default/multideployer.ear, Cause: java.lang.NullPointerException
      at org.jboss.deployment.J2eeDeployer.startModules(J2eeDeployer.java:521)
      at org.jboss.deployment.J2eeDeployer.startApplication(J2eeDeployer.java:444)
      at org.jboss.deployment.J2eeDeployer.deploy(J2eeDeployer.java:215)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1628)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
      at org.jboss.deployment.AutoDeployer.deploy(AutoDeployer.java:654)
      at org.jboss.deployment.AutoDeployer.run(AutoDeployer.java:327)
      at java.lang.Thread.run(Unknown Source)


      Any Ideas??? Anyone? I really dont need it for this bean, but I have some other beans which I really need EJB-QL for and I thought a simple example of the problem would be easiest to show.

      Al

        • 1. Re: EJB-QL Problem
          Jochen Cordes Novice

          Hi !

          I just saw a little mistake in the entity-part of Users. You should remove the cmr-field-part (it's not supported by the DTD). Declaring the field in the relation part is sufficient. I hope that you left out the ejbXXX-methods (they are missing in your quote). Why do you return Users in your create-methods and not UsersLocal (as you did in Users for Demographics) ?

          Hope it helps,

          Jochen.

          • 2. Re: EJB-QL Problem
            Allen Fogleson Newbie

            I dont know why I had that cmr-field in there. I think I was following monson-haefels examples... it still deploys with it as long as there is no EJB-QL included. ohh well its gone and that didnt solve anything.

            I dont have any EJBSelects in this entity, so they are not included. Like I said this is a very simple bean... with only a relationship that really makes CMP 2 nice. But I cannot get the EJB-QL to work at all.

            Im feeling like a regular idiot :)

            I get an arrayIndexOutOfBounds exception if I add in an ejbSelect method, and its appropriate query. (which seems better than a NullPointerException, at least it seems to process the EJB-QL then. I guess ill have to pull out the code and see where that leads.

            If you have an example that works i would love to get an email with the jar. Then maybe I can see if my version of 3.0Alpha has a bug or something.

            Al

            • 3. Re: EJB-QL Problem
              Allen Fogleson Newbie

              Actually I answered this myself. There was another error in there. EJB-QL is case sensitive and i had "where" instead of "WHERE". I still occasionally have problems, but I have found that if I have JBuilder rebuild everything then it works fine.

              Al