1 Reply Latest reply on Jul 24, 2002 11:43 AM by Eric Isakson

    Ejb CMP update problems with Jboss3.0.0 and xdoclet

    Diego Newbie

      When I try to update the values of a table in the database I use this code:

      *************************************************
      public void setValueObject( EntityTypeData pEntityType )
      throws InvalidValueException
      {
      EntityType lEntityType = null;
      EntityTypeHome lHome = null;
      if( pEntityType == null ) {
      throw new invalidValueException("object.undefined", "EntityType" );
      }
      if( pEntityType.getEntityTypeId() <= 0 ) {
      throw new InvalidValueException( "id.invalid", new String[] { "EntityType", "EntityTypeId" } );
      }
      try {
      lHome = (EntityTypeHome) mContext.getEJBHome();
      lEntityType = lHome.findByEntityTypeId( pEntityType.getEntityTypeId());
      }
      catch( FinderException fe ) {
      setEntityTypeId (pEntityType.getEntityTypeId());
      }
      catch( RemoteException re ) {}


      setName (pEntityType.getName());

      System.out.println(pEntityType.getName());
      System.out.println(getName());

      }

      ****************************************************

      In then last two lines i see that the value in de EntityBean is the same that i want but the bean lost this value when I try to get this value later.

      Thaks

        • 1. Re: Ejb CMP update problems with Jboss3.0.0 and xdoclet
          Eric Isakson Newbie

          I had a similar problem using the template code. I cranked up the logging yesterday in server\default\conf\log4j.xml and found that the jdbc plugin couldn't find a query for my finder:

          javax.ejb.FinderException: Unknown query: public abstract com.sas.pubs.cmpproblem.interfaces.CMPEntityLocal com.sas.pubs.cmpproblem.interfaces.CMPEntityLocalHome.findAnotherByName(int,java.lang.String) throws javax.ejb.FinderException

          at org.jboss.ejb.plugins.cmp.jdbc.JDBCQueryManager.getQueryCommand(JDBCQueryManager.java:56)

          This prevented my changes from being updated to the DB.

          The template code uses @jboss:finder-query to define the SQL where clause for the finder which puts the clause in jaws.xml.

          * @ejb:finder signature="com.sas.pubs.mimir.interfaces.RepositoryEntityLocal findAnotherByName( int pId, java.lang.String pName )"
          * view-type="local"
          *
          * @jboss:finder-query name="findAnotherByName"
          * query="Id != {0} AND Name = {1}"

          You need to use the query attribute of the @ejb:finder tag to define an EJB-QL query instead like (I haven't had a chance to fix mine yet, but I'm 99% sure this is going to fix it):


          * @ejb:finder signature="com.sas.pubs.cmpproblem.interfaces.CMPEntityLocal findAnotherByName( int pId, java.lang.String pName )"
          * query="SELECT ENTITY(c) FROM CMPEntity c WHERE c.Id != ?1 AND c.Name = ?2"
          * view-type="local"

          I can't remember if view-type="local" worked out of the box with xdoclet 1.1.2, I think I had to go hack the template to get that working.

          Make sure your ejb names follow the rule defined in docs\dtd\ejb-jar_2_0.dtd:
          The name for an entity bean with cmp-version 2.x must conform to the lexical rules for an NMTOKEN. The name for an entity bean with cmp-version 2.x must not be a reserved literal in EJB QL.

          The one in the template is named "test/TestEntity" which is not an NMTOKEN.

          The names only have to be unique within the names deployed in the same ejb-jar file.

          I'm not sure if the rules here really apply to the bean name or if they are supposed to apply to the abstract schema name (which you can define using the "schema" parameter of the @ejb:bean tag).

          There is a wealth of information in the comments of the ejb-jar_2_0.dtd file that I've been using as I struggle to learn these great technologies. Definitely worth looking through that resource.

          Hope this helps!

          Good luck,
          Eric