5 Replies Latest reply on Aug 14, 2002 7:31 AM by Nir Oren

    xdoclet 1 to Many relationship @jboss:relation tag

    Ruben Ramirez Newbie

      I'm having problems getting a one to many relationship to work and I'm using xdoclet to generate the code. I can't seem to get the ejb:relation and @jboss:relation working.
      Here's the info:

      I have 2 tables Account and Address. An account has many addresses and here's the table definition:

      Account(accountId,email,name,passcode,....)
      Address(addressId,accountId,addrType,line1,line2,city,state,zip)

      Account.accountId and Address.addressId are primary keys.
      Address.accountId references Account.accountId.

      The following is from the AccountBean:
      Here's the ejb:bean info:

      * @ejb:bean name="andrea/AccountBean"
      * display-name="The Account Bean"
      * type="CMP"
      * jndi-name="ejb/andrea/Account"
      * local-jndi-name="ejb/andrea/AccountLocal"
      * view-type="both"
      * schema="Account"


      Here's the getter's
      /**
      * @return Returns the accountId
      *
      * @ejb:persistent-field
      * @ejb:pk-field
      *
      * @jboss:column-name name="accountId"
      * @jboss:sql-type INTEGER
      * @jboss:jdbc-type INTEGER
      */
      public abstract Integer getId();

      /**
      * @return Returns the email address for this account.
      *
      * @ejb:persistent-field
      *
      * @jboss:column-name name="email"
      * @jboss:sql-type VARCHAR(80)
      * @jboss:jdbc-type VARCHAR
      */
      public abstract String getEmail();

      /**
      * @return Returns the passcode for this account
      *
      * @ejb:persistent-field
      *
      * @jboss:column-name name="passcode"
      * @jboss:sql-type VARCHAR(40)
      * @jboss:jdbc-type VARCHAR
      */
      public abstract String getPasscode();

      Here's the relationship I'm trying to use


      /**
      * @ejb:interface-method view-type="both"
      *
      * @ejb:relation name="Account-Address"
      * role-name="Account-Has-Many-Addresses"
      * target-role-name="Address-Has-One-Account"
      * target-ejb="andrea/AddressBean"
      * cascade-delete="no"
      *
      * @jboss:relation fk-constraint="false"
      * related-pk-field="id"
      * fk-column="accountId"
      *
      */
      public abstract java.util.Collection getAddresses();

      /**
      * @ejb:interface-method view-type="both"
      */
      public abstract void setAddresses(java.util.Set addresses);



      ============================================================================================
      The following is from the address:
      Here's the ejb:bean info:

      * The Address bean. Holds address information for accounts.
      * @ejb:bean name="andrea/AddressBean"
      * display-name="The Address Bean"
      * type="CMP"
      * jndi-name="ejb/andrea/Address"
      * local-jndi-name="ejb/andrea/AddressLocal"
      * view-type="both"
      * schema="Address"


      Here's the getter info
      /**
      * @return The key identifying the Address
      * @ejb:persistent-field
      * @ejb:pk-field
      *
      * @jboss:column-name name="addressId"
      * @jboss:sql-type INTEGER
      * @jboss:jdbc-type INTEGER
      */
      public abstract Integer getId();


      /**
      * @return The key identifying the account
      * @ejb:persistent-field
      *
      * @jboss:column-name name="accountId"
      * @jboss:sql-type INTEGER
      * @jboss:jdbc-type INTEGER
      */
      public abstract Integer getAccountId();

      /**
      * @return The type of address
      * @ejb:persistent-field
      *
      * @jboss:column-name name="addrType"
      * @jboss:sql-type VARCHAR(2)
      * @jboss:jdbc-type VARCHAR
      */
      public abstract String getType();

      /**
      * @return The first line of the address field
      * @ejb:persistent-field
      *
      * @jboss:column-name name="line1"
      * @jboss:sql-type VARCHAR(30)
      * @jboss:jdbc-type VARCHAR
      */
      public abstract String getLine1();

      /**
      * @return The second line of the address field. This is optional
      * @ejb:persistent-field
      *
      * @jboss:column-name name="line2"
      * @jboss:sql-type VARCHAR(30)
      * @jboss:jdbc-type VARCHAR
      */
      public abstract String getLine2();

      /**
      * @return The city of the address field.
      * @ejb:persistent-field
      *
      * @jboss:column-name name="city"
      * @jboss:sql-type VARCHAR(30)
      * @jboss:jdbc-type VARCHAR
      */
      public abstract String getCity();

      /**
      * @return The state
      * @ejb:persistent-field
      *
      * @jboss:column-name name="state"
      * @jboss:sql-type VARCHAR(2)
      * @jboss:jdbc-type VARCHAR
      */
      public abstract String getState();

      /**
      * @return The zip code
      * @ejb:persistent-field
      *
      * @jboss:column-name name="zip"
      * @jboss:sql-type VARCHAR(10)
      * @jboss:jdbc-type VARCHAR
      */
      public abstract String getZip();


      Any help would be greatly appreciated.

      Thanks,
      Ruben