5 Replies Latest reply on Aug 13, 2002 4:41 PM by jhudsy

    Newbie problems

    jhudsy

      Hi...

      I'm quite a newbie to jboss (and j2ee in general), and am having no end of trouble getting started:

      I'm attempting to create a state machine using a number of entity beans: State, Transition, and ProcessInstance. The ProcessInstance bean represents an actual instantiation of the state machine. State consists of some state data, together with a collection of transitions, and transition consists of a source state, a target state, and a list of validators that must be true if the transition is to be allowed. ProcessInstance contains a reference to the current state.

      Using xdoclet, I ended up with the jbosscmp-jdbc.xml file shown at the end of this message (I'm getting an error trying to attach files). When I attempt to deploy my code with this file, I end up getting a javax.management.InstanceAlreadyExistsException exception. If I remove the section of the file, the code deploys OK, but then does not work as desired. I use xdoclet tags similar to the following:

      @ejb:relation name="CurrentState-relation"
      role-name="current-state"
      target-role-name="the-state"
      target-ejb="State"
      target-multiple="yes"

      (I've tried adding @jboss:relation tags, with no luck)

      to indicate that the currentState for a processInstance is a unidirectional relationship, and that many processInstances could point to one state. This relation appears in my ProcessInstance file. I have similar tags to deal with states and processes, with one bidirectional relation indicating that a transition's source state can hold many transitions.

      As you may be able to tell from this message, I have no idea why none of this is working. The mistakes (as far as I can tell) could lie in a number of places:
      1) I am misunderstanding how to use relationships in CMP
      2) I am misusing the xdoclet tags
      3) I am misusing jboss.

      I'm using postgres 7.2.1 as my backend db, running jboss-3.0.0 (I'm downloading 3.0.1 as I type), xdoclet 1.1.2, and java 1.4 all under linux.

      Any and all help would be greatly appreciated.
      Nir Oren

      The relations extract of my jbosscmp-jdbc.xml file:

      <ejb-relation>
      <ejb-relation-name>SourceState-Transition-Relation</ejb-relation-name>
      <foreign-key-mapping/>
      <ejb-relationship-role>
      <ejb-relationship-role-name>state-has-many-possible-transitions</ejb-relationship-role-name>
      <key-fields/>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>state-from-which-we-transition</ejb-relationship-role-name>
      <key-fields/>
      </ejb-relationship-role>
      </ejb-relation>
      <ejb-relation>
      <ejb-relation-name>TargetState-Transition-Relation</ejb-relation-name>
      <foreign-key-mapping/>
      <ejb-relationship-role>
      <ejb-relationship-role-name>target-state</ejb-relationship-role-name>
      <key-fields/>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>target-for-transition-state</ejb-relationship-role-name>
      <key-fields/>
      </ejb-relationship-role>
      </ejb-relation>
      <ejb-relation>
      <ejb-relation-name>CurrentState-relation</ejb-relation-name>
      <foreign-key-mapping/>
      <ejb-relationship-role>
      <ejb-relationship-role-name>current-state</ejb-relationship-role-name>
      <key-fields/>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>the-state</ejb-relationship-role-name>
      <key-fields/>
      </ejb-relationship-role>
      </ejb-relation>

        • 1. Re: Newbie problems
          dsundstrom

          First, make sure you are using the most current version of XDoclet. I'm not an XDoclet expert, but here is the tag I use:

          * @ejb:relation
          * name="User-Post"
          * role-name="Post-belongs-to-a-User"

          I don't have the other elements. XDoclet is definitely a less is more tool.

          • 2. Re: Newbie problems
            jhudsy

            Hi...

            Trying the tag just like that gives me an error:

            [ejbdoclet] <<xdoclet.XDocletException: The relation with the name "TargetState-Transition-Relation" declared in TransitionBean.getTargetState seems to be unidirectional since it does not occur anywhere else. The target-ejb parameter must therefore be specified.>>

            Does anyone have an example of using xdoclet to generate a unidirectional one to many relation in JBoss?
            Thanks
            Nir

            • 3. Re: Newbie problems
              jhudsy

              Hi...

              I managed to solve my problem with the xdoclet tags, but am now facing
              further obstacles:

              The database seems to have been created as appropriate, but when I try to
              set a unidirectional field, it appears not to get updated in the db. The
              following code extract illustrates this:

              /** @ejb:relation name="TargetState-Transition-Relation"
              * role-name="transition-target"
              * target-role-name="target-state-for-this-transition"
              * target-ejb="State"
              * target-multiple="yes"
              * @ejb:interface-method view-type="local"
              * @jboss:relation related-pk-field="stateID" fk-column="targetstate"
              */
              public abstract StateLocal getTargetState();

              /**@ejb:interface-method view-type="local"*/
              public abstract void setTargetState(StateLocal state);

              /**@ejb:interface-method view-type="remote"*/
              public void updateTargetState(State state) throws Exception
              {
              StateLocal ts=((StateLocal) ((StateLocalHome) (new
              InitialContext()).lookup("StateLocal")).findByPrimaryKey((StatePK)
              state.getPrimaryKey()));
              setTargetState(ts);
              System.out.println(ts);
              System.out.println("ts:"+getTargetState());
              }

              When I call updateTargetState(...), the println prints the right thing.
              However, if I call getTargetState() in a later method, I get null back.
              Looking in the database, the field is always empty.
              I've got another set of methods that operate in a similar manner, they
              also never seem to update the database.

              Also a hopefully unrelated problem that is appearing is that I get

              java.rmi.ServerException: Internal error getting results for field member
              contextID

              errors at random intervals when trying to use some of my methods. This
              error appears only sporadically. contextID is a java object (which does
              extend java.io.Serializable), and is stored as a bytea type within the
              database.

              My backend db is postgresql 7.2.1, and I'm running jBoss 3.0.0.

              Any and all help will be greatly appreciated
              Nir

              • 4. Re: Newbie problems
                dsundstrom

                Upgrade to 3.0.1 final and the problem will go away.

                • 5. Re: Newbie problems
                  jhudsy

                  Hi...

                  Many thanks, it worked, BUT, as I mention in the thread at
                  http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/ still get bitten by another problem. I have filed a bug report on sourceforge.
                  Many thanks for all the help
                  Nir