I figured this out... dumb mistake... the getDog() method had @ejb.persistent-field AND @ejb.relation xdoclet tags. I removed the @ejb.persistent-field tag, it was causing a <cmp-field> element to be generated.


From: ll <[EMAIL PROTECTED]>
Date: February 10, 2004 15:29:00 EST
To: [EMAIL PROTECTED]
Subject: [CMR] NullPointerException when compiling EJB-QL query (many-to-one unidirectional relationship)


I have a unidirectional many-to-one relationship between FleaEJB (many) and DogEJB (one). At least I think that's correct: each flea can refer to only one dog, but many fleas can refer to the same dog.

I want to find all fleas that refer to a given dog, but I get a NullPointerException from JBoss when compiling the EJB-QL query when deploying:

14:47:28,135 INFO [Dog] Created table 'DOG' successfully.
14:47:29,259 INFO [Flea] Created table 'FLEA' successfully.
14:47:29,291 ERROR [EntityContainer] Starting failed
org.jboss.deployment.DeploymentException: Error compiling EJB-QL statement 'select object(f) from Flea as f where f.dog = ?1'; - nested throwable: (java.lang.NullPointerException)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.<init>(JDBCEJBQLQuery.jav a:50)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCCommandFactory.createEJBQLQuery(JDBC CommandFactory.java:59)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCQueryManager.start(JDBCQueryManager. java:212)
...


What am I doing wrong? I'm pretty sure the <relationships> section of my ejb deployment descriptor is correct because it matches the cruise --> ship example in the O'Reilly EJB flea (p208).
I suspect that there is something wrong with my jbosscmp-jdbc.xml (attached below).


Any ideas? Thanks in advance!!


-------------------- Here are my configuration files:

Flea EJB:

/**
* @ejb.bean
* name = "Flea"
* type = "CMP"
* jndi-name = "ejb/Flea"
* local-jndi-name = "ejb/LocalFlea"
* primkey-field = "fleaId"
*
* @ejb.finder
* signature = "java.util.Collection findByDog(com.me.testapp.ejbclient.Dog dog)"
* query = "select object(f) from Flea as f where f.dog = ?1"
* unchecked = "true"
*
* @ejb.value-object
*
* @ejb.pk
* unchecked = "true"
*/
public abstract class FleaEJB implements EntityBean {
...


        /**
         * @ejb.persistent-field
         * @ejb.relation
         *     name = "Flea-Dog"
         *     role-name = "Flea-has-a-Dog"
         *     target-ejb = "Dog"
         *     target-role-name = "Dog-has-many-Fleas"
         *     target-multiple = "true"
         *
         * @jboss.relation
         *     related-pk-field = "dogId"
         *     fk-column = "dogIdFk"
         */
        public abstract Dog getDog();

        /**
         * @ejb.persistent-field
         */
        public abstract void setDog(Dog dog);
...
}


Dog EJB:


/**
 * @ejb.bean
 *     name = "Dog"
 *     type = "CMP"
 *     jndi-name = "ejb/Dog"
 *     local-jndi-name = "ejb/LocalDog"
 *     primkey-field = "dogId"
 * @ejb.value-object
 *
 * @ejb.pk
 *     unchecked = "true"
 */
public abstract class DogEJB implements EntityBean {
...
}


From ejb-jar.xml (generated by xDoclet):


      <entity >
         <ejb-name>Flea</ejb-name>

<home>com.me.testapp.ejbclient.FleaHome</home>
<remote>com.me.testapp.ejbclient.FleaRemote</remote>
<local-home>com.me.testapp.ejbclient.FleaLocalHome</local-home>
<local>com.me.testapp.ejbclient.Flea</local>


         <ejb-class>com.me.testapp.ejb.FleaCMP</ejb-class>
         <persistence-type>Container</persistence-type>
         <prim-key-class>java.lang.String</prim-key-class>
         <reentrant>False</reentrant>
         <cmp-version>2.x</cmp-version>
         <abstract-schema-name>Flea</abstract-schema-name>
         <cmp-field >
            <field-name>dog</field-name>
         </cmp-field>
         <primkey-field>fleaId</primkey-field>

<query>
<query-method>
<method-name>findByDog</method-name>
<method-params>
<method-param>com.me.testapp.ejbclient.Dog</method-param>
</method-params>
</query-method>
<ejb-ql><![CDATA[select object(f) from Flea as f where f.dog = ?1]]></ejb-ql>
</query>


      </entity>
...
   <relationships >
      <ejb-relation >
         <ejb-relation-name>Flea-Dog</ejb-relation-name>

<ejb-relationship-role >
<ejb-relationship-role-name>Flea-has-a-Dog</ejb-relationship-role- name>
<multiplicity>Many</multiplicity>
<relationship-role-source >
<ejb-name>Flea</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>dog</cmr-field-name>
</cmr-field>
</ejb-relationship-role>


<ejb-relationship-role >
<ejb-relationship-role-name>Dog-has-many-Fleas</ejb-relationship-role- name>
<multiplicity>One</multiplicity>
<relationship-role-source >
<ejb-name>Dog</ejb-name>
</relationship-role-source>
</ejb-relationship-role>


      </ejb-relation>
   </relationships>
...


From jbosscmp-jdbc.xml (generated by xDoclet):


  <relationships>
    <ejb-relation>
      <ejb-relation-name>Flea-Dog</ejb-relation-name>

<foreign-key-mapping/>

<ejb-relationship-role>
<ejb-relationship-role-name>Flea-has-a-Dog</ejb-relationship-role- name>
<key-fields/>


</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>Dog-has-many-Fleas</ejb-relationship-role- name>
<key-fields>
<key-field>
<field-name>dogId</field-name>
<column-name>dogIdFk</column-name>
</key-field>
</key-fields>


      </ejb-relationship-role>
    </ejb-relation>
  </relationships>

The tables that are generated (from hypersonic/localDB.script):

CREATE TABLE DOG (dogId VARCHAR(256) NOT NULL, firstName VARCHAR(256), lastName VARCHAR(256), birthDate VARCHAR(256), phoneNumber VARCHAR(256), CONSTRAINT PK_DOG PRIMARY KEY (dogId))
CREATE TABLE FLEA (fleaId VARCHAR(256) NOT NULL, libraryCode VARCHAR(256), title VARCHAR(256), authorName VARCHAR(256), dog VARBINARY, dogIdFk VARCHAR(256), CONSTRAINT PK_FLEA PRIMARY KEY (fleaId))





------------------------------------------------------- The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. http://www.eclipsecon.org/osdn _______________________________________________ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to