3 Replies Latest reply on Sep 20, 2005 5:18 PM by Danny Van Woensel

    jboss 4.0.2 ejb 2.1 ejb-ql order by problem

    Danny Van Woensel Newbie

      Hi,

      I try to order the result of the finder by id. But it won't order; it is always the same ordering, whatever I do or specify in the ejb-ql. First I used JBoss 3.2 and tried to order the result of the finder by overriding the ejb-ql by jboss-ql. It did not work for me and after I've read somewhere that ejb 2.1 supported "order by" I changed to JBoss 4.0.2. But the problem remains. I've searched the forum and the internet for a possible solution, but with no luck so far. Can anyone help me with this?

      Specs:
      - JBoss 4.0.2
      - JDK1.5.0_01
      - XDoclet 1.2.3
      - Eclipse

      Libs I use from jboss/client:
      - axis-ws4ee.jar
      - jbossall-client.jar
      - jboss-j2ee.jar
      - jboss-jaxrpc.jar
      - jboss-saaj.jar
      - jnp-client.jar
      - log4j.jar

      EntityBean:

      /**
       * Entitybean for an agent
       *
       * @ejb.bean
       * cmp-version = "2.x"
       * jndi-name = ".../Agent"
       * name = "Agent"
       * primkey-field = "id"
       * type = "CMP"
       * view-type = "local"
       *
       * @ejb.finder
       * signature = "java.util.Collection findAll()"
       * query = "select object(a) from Agent as a"
       *
       * @ejb.finder
       * signature = "java.util.Collection findAllLike(java.lang.String lastname)"
       * query = "select object(a) from Agent as a where a.lastname like ?1 order by a.id asc"
       *
      
      OR
      
       * @ejb.finder
       * signature = "java.util.Collection findAllLike(java.lang.String lastname)"
       * query = "Overridden by jbosscmp-jdbc.xml"
       *
       * @jboss.query
       * signature = "java.util.Collection findAllLike(java.lang.String lastname)"
       * query = "select object(a) from Agent as a where a.lastname like ?1 order by a.id asc"
       *
       */
      
      public abstract class AgentBean implements EntityBean {
      
       /**
       * ejbCreate method with valueobject
       *
       * @param agent AgentData
       * @return Returns null
       * @throws CreateException
       *
       * @ejb.create-method
       */
       public Object ejbCreate(AgentData agent) throws CreateException {
       try {
       setId(Sequencer.getInstance("Agent").next());
       } catch (SQLException e) {
       throw new CreateException("Failed to create primary-key");
       } catch (NamingException e) {
       throw new CreateException("Failed to create primary-key");
       }
       return null;
       }
      
       /**
       * Empty ejbPostCreate method
       *
       * @param agent AgentData
       * @throws CreateException
       */
       public void ejbPostCreate(AgentData agent) throws CreateException {
       }
      
       /**
       * Accessor for the primary-key (id)
       *
       * @return Returns the primary-key (id)
       *
       * @ejb.interface-method
       * @ejb.persistence
       * @ejb.pk-field
       */
       public abstract Integer getId();
      
       /**
       * Mutator for the primary-key (id)
       *
       * @param id Integer
       */
       public abstract void setId(Integer id);
      
       /**
       * Accessor for the lastname
       *
       * @return Returns the lastname
       *
       * @ejb.interface-method
       * @ejb.persistence
       * jdbc-type = "VARCHAR"
       * sql-type = "VARCHAR(255)"
       */
       public abstract String getLastname();
      
       /**
       * Mutator for the lastname
       *
       * @param lastname The lastname
       *
       * @ejb.interface-method
       */
       public abstract void setLastname(String lastname);
      }
      


      ejb-jar.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      
      <ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd" version="2.1">
      
       <description>[CDATA[No Description.]]</description>
       <display-name>Generated by XDoclet</display-name>
      
       <enterprise-beans>
       ...
       <session >
       <description>[CDATA[]]</description>
       <ejb-name>AgentManager</ejb-name>
       <local-home>com.aristomusic.cougar.interfaces.AgentManagerLocalHome</local-home>
       <local>com.aristomusic.cougar.interfaces.AgentManagerLocal</local>
       <ejb-class>com.aristomusic.cougar.session.manager.AgentManagerBean</ejb-class>
       <session-type>Stateless</session-type>
       <transaction-type>Container</transaction-type>
       </session>
       ...
       <entity >
       <description>[CDATA[]]</description>
       <ejb-name>Agent</ejb-name>
      
       <local-home>interfaces.AgentLocalHome</local-home>
       <local>interfaces.AgentLocal</local>
      
       <ejb-class>.interfaces.AgentCMP</ejb-class>
       <persistence-type>Container</persistence-type>
       <prim-key-class>java.lang.Integer</prim-key-class>
       <reentrant>false</reentrant>
       <cmp-version>2.x</cmp-version>
       <abstract-schema-name>Agent</abstract-schema-name>
       <cmp-field >
       <description>[CDATA[Accessor for the primary-key (id)]]</description>
       <field-name>id</field-name>
       </cmp-field>
       <cmp-field >
       <description>[CDATA[Accessor for the lastname]]</description>
       <field-name>lastname</field-name>
       </cmp-field>
       <primkey-field>id</primkey-field>
      
       <query>
       <query-method>
       <method-name>findAll</method-name>
       <method-params>
       </method-params>
       </query-method>
       <ejb-ql>[CDATA[select object(a) from Agent as a]]</ejb-ql>
       </query>
       <query>
       <query-method>
       <method-name>findAllLike</method-name>
       <method-params>
       <method-param>java.lang.String</method-param>
       </method-params>
       </query-method>
       <ejb-ql>[CDATA[select object(a) from Agent as a where a.lastname like ?1 order by a.id asc]]</ejb-ql>
       </query>
      
       OR
      
       <query>
       <query-method>
       <method-name>findAllLike</method-name>
       <method-params>
       <method-param>java.lang.String</method-param>
       </method-params>
       </query-method>
       <ejb-ql>[CDATA[Overridden by jbosscmp-jdbc.xml]]</ejb-ql>
       </query>
       <!-- Write a file named ejb-finders-AgentBean.xml if you want to define extra finders. -->
       </entity>
       ...
      


      build.xml:
      <property file="${basedir}/ant-global.properties" />
      <property file="${basedir}/build.properties" />
      
      <path id="xdoclet.classpath">
       <pathelement location="${basedir}/bin" />
       <pathelement location="${basedir}/lib/jboss-j2ee.jar" />
       <fileset dir="${xdoclet.path}/lib/">
       <include name="*.jar" />
       </fileset>
      </path>
      
      <target name="XDoclet">
       <taskdef classpathref="xdoclet.classpath" classname="xdoclet.modules.ejb.EjbDocletTask" name="ejbdoclet" />
       <delete dir="${build.bindir}/*" />
       <delete>
       <fileset dir="${build.sourcedir}/META-INF">
       <include name="ejb-jar.xml" />
       <include name="jboss.xml" />
       <include name="jbosscmp-jdbc.xml" />
       </fileset>
       </delete>
       <delete>
       <fileset dir="${build.sourcedir}/com/aristomusic/cougar/interfaces">
       <include name="*.java" />
       </fileset>
       </delete>
       <ejbdoclet ejbSpec="2.1" destDir="${build.sourcedir}">
       <dataobject destDir="${build.sourcedir}" />
       <fileset dir="src" includes="**/*Bean.java" />
       <deploymentdescriptor destDir="src/META-INF" />
       <jboss Version="4.0" datasource="java:/DefaultDS" datasourceMapping="mySQL" destDir="src/META-INF" />
       <packagesubstitution packages="entity,session.manager,session.process" substituteWith="interfaces" />
       <utilobject localproxies="true" kind="physical" />
       <homeinterface />
       <localhomeinterface />
       <localinterface />
       <remoteinterface />
       <entitycmp destDir="src">
       <PackageSubstitution packages="entity" substituteWith="interfaces" />
       </entitycmp>
       </ejbdoclet>
      </target>
      
      <target name="Compile" depends="XDoclet">
       <mkdir dir="${basedir}/${build.bindir}" />
       <javac srcdir="${build.sourcedir}" destdir="${build.bindir}" debug="on">
       <classpath>
       <fileset dir="${basedir}">
       <include name="*.jar" />
       <include name="lib//*.jar" />
       </fileset>
       </classpath>
       </javac>
      </target>