5 Replies Latest reply on Mar 13, 2002 1:35 PM by Alice

    Relationships in EJB 1.1

    Alice Newbie

      I have a 1:n relationship in my database schema between COMPANY & EMPLOYEES. COMPANY will be represented as an entity bean. Is there a recommended way to represent this 1-to-many relationship between Company (an entity bean) & Employee (Employee can be an entity bean or a dependent object to be stored in database) in EJB 1.1 ??

      Thank you.

        • 1. Re:  Relationships in EJB 1.1
          Marcus Brito Novice

          Relationships are akward in EJB 1.1 since it doesn't have container manager relationships. Are your beans going to be CMP or BMP?

          As Employees are going to be used by themselves, not anly as a Company aggregate (is that right? Employee seems to be a useful entity to me), code it as an Entity bean. Write a value object wrapper for it and return a collection of value objects in the Company's accessor method.

          public Collection getEmployees();
           ^^^^^^^^^^
           Collection of EmployeeValue
          

          Anyway, if you have the courage, you could try JBoss 3.0.0beta and code everything container managed. Make your beans CMP and define a container managed relationship between them.

          Hey, this is my 100th post!

          • 2. Re:  Relationships in EJB 1.1
            Alice Newbie

            I want them to be CMP. Does that mean I'll have to create foreign key manually? And I'll have to get the "collection of employees" by making jdbc calls myself? So essentially I am making it a CMP and yet writing a lot of persistence myself?? I mean it seems like CMP is very limited in EJB 1.1..

            Im a little afraid of using Jboss3.0 beta. Is it too buggy?

            Thanks very much.

            • 3. Re:  Relationships in EJB 1.1
              Dain Sundstrom Master

              I am sure that it is less buggy then writing a couple thousand lines of code to manage relationships.

              • 4. Re:  Relationships in EJB 1.1
                Marcus Brito Novice

                Yes, CMP is very limited in EJB 1.1. As David pointed out, JBoss 3.0 may still be buggy (the horror! the horror!), but sure it is less buggy then writing thousand of JDBC/SQL code.

                As another *great* option, you can stick to JBoss 2.4.x and use MVCSoft persistence manager. This is a great product that enables you to use CMP 2.0 in JBoss 2.4.x and other application servers. It costs a few bucks, but sure it's worth the money. Take a look at http://www.mvcsoft.com

                • 5. Re:  Relationships in EJB 1.1
                  Alice Newbie

                  Thank you guys for all the help.