2 Replies Latest reply on Jun 2, 2004 9:27 AM by Tibor Pasztorka

    Foreign key referencing not the primary key

    Tibor Pasztorka Newbie

      I'd like to create a one to many relationship.

      I know that the many side must contain a foreign key referencing the primary key of the one side.

      Is it permitted for the foreign key to point not to the primary key of the one side but to a common CMP field?

      Moreover, I'd like to make this relationship unidirectional to the one side, using a Collection typed CMR field.

      How this could be accomplished using XDoclet?

      Thanks in advance.

      Tibor

        • 1. Re: Foreign key referencing not the primary key
          ironbird Newbie

           


          Is it permitted for the foreign key to point not to the primary key of the one side but to a common CMP field?

          No, the foreign key constraint must be with a primary key.


          Moreover, I'd like to make this relationship unidirectional to the one side, using a Collection typed CMR field.
          How this could be accomplished using XDoclet?

          Here is it:
           * @ejb.interface-method
           * @ejb.relation
           * name="BeanA in relation with BeanB"
           * role-name="BeanA-has-many-BeanB"
           * target-ejb="BeanB"
           * target-role-name = "BeanB-has-one-BeanA"
           *
           * @jboss.target-relation
           * fk-column = <The column name in the table for BeanB>
           * related-pk-field = <The BeanA cmp field name (primary key)>
           */
           public abstract java.util.Collection getBeanBs();
          
          
           /**
           * @ejb.interface-method
           */
           public abstract void setBeanBs(java.util.Collection arg);