1 Reply Latest reply on Jun 26, 2002 7:41 PM by Dain Sundstrom

    need examples on custom findBy methods in Jboss 3.0 latest v

    Travel Maniac Newbie

      I am trying to create custom findBy methods. In this case, I want to find a user based on both username and password. I _thought_ it was a simple matter of creating a tag in the ejb-jar.xml. Such as this:

      <![CDATA[ SELECT OBJECT(a) FROM vector_user WHERE username = ?1 AND password = ?2   ]]>

      But when I tried to deploy the bean with this, I get a slew of error messages, the one in particular is:

      + nested throwable:
      org.jboss.deployment.DeploymentException: Error compiling ejbql; - nested throwable: (org.jboss.ejb.plugins.cmp.ejbql.ParseException: Encountered "vector_user" at line 2, column 55.
      Was expecting one of:
      "IN" ...

      So I am wondering how this is really done. I have only found examples of using jaw.xml in JBoss2.2.4. That is not useful for me using 3.0.

      Thanks in advance!

        • 1. Re: need examples on custom findBy methods in Jboss 3.0 late
          Dain Sundstrom Master

          I suggest read the free EJB 2.0 (PDF) book available at the serverside.com or get a copy of the O'Reilly EJB book.

          EJB-QL is based on the abstract schema of the entity beans. The from clause uses the abstract-schema-name declared for the entity in the ejb-jar.xml file (not the table name), and the where clause uses the cmp-field name. Your query should look something like this:
          SELECT OBJECT(a)
          FROM vector_user a
          WHERE a.username = ?1 AND a.password = ?2
          Notice I added the alias declaration a, and used that alias in the where clause. This query assumes that the abstract-schema-name vector_user is valid and it has username and password cmp fields.