5 Replies Latest reply on Apr 10, 2002 5:06 PM by kantek

    Many-to-Many relationship with cmp

    dharfleet

      Hi,

      I have three entities:

      I have three database tables, say for example:

      USER, ROLE and USER_ROLE

      USER and ROLE both have a pk and USER_ROLE uses the pk from USER and ROLE to map the many to many relationship.

      I want to use CMP, but want to make sure I still have the third table (USER_ROLE) created by jaws.

      I will be using a session facade, but would still prefer to manage the relationship with a database table, so that I can view this relationship from other non ejb applications.


      Does anyone know the best approach to designing the 'user_role' Entity bean, should I just have the fk fields in the bean, or a User and a Role entity in there ?

      many thanks
      dan

        • 1. Re: Many-to-Many relationship with cmp
          ryanramage

          I am having the same problem. Any solutions yet?

          • 2. Re: Many-to-Many relationship with cmp
            foglesa

            In ejb 1.1 im not even sure I would use an entity bean for the user_role table. Of course if you are feeling adventurous you could look at jboss 3 alpha and use CMP2 with the relationships to do this much easier.

            The overhead of an entity bean for a mapping table just doesnt make sense to me really in 1.1. Of course IMHO the or mapping in 1.1 was/is lacking anyway.

            Al

            • 3. Re: Many-to-Many relationship with cmp
              erik777

              I created a UserRole CMP. While I understand that 1.1 is lacking, I am counting on being able to upgrade it to 2.0 when JBoss 3 is ready. Believe me, I am waiting anxiously for 3.0.

              Here's the bean:

              [pre]
              public class UserRoleBean extends BaseCMPBean {

              // Private persistent properties
              public Integer userId, roleId ;

              /**
              * Create an instance of a bean. Note that this method returns null because the real
              * creation is managed by the EJB container.
              */
              public Integer ejbCreate (Integer _userId, Integer _roleId )
              {
              setUserId(_userId);
              setRoleId(_roleId);
              return null;
              }

              public void ejbPostCreate(Integer _userId, Integer _roleId ) { }

              public Integer getUserId() { return userId; }
              public void setUserId(Integer _userId) { userId = _userId; }

              public Integer getRoleId() { return roleId; }
              public void setRoleId(Integer _roleId) { roleId = _roleId; }
              }
              [/pre]

              • 4. Re: Many-to-Many relationship with cmp
                foglesa
                • 5. Re: Many-to-Many relationship with cmp
                  kantek

                  But if i don't want a EJB to make the binding between the 2 entities ? How i do this ?