3 Replies Latest reply on Apr 25, 2004 6:07 AM by triathlon98

    Beginner needs help with modelisation issue

    balteo

      Hello, I have four tables in a relational database.

      *First table, called "establishments", contains two fiels "db_establishment_id" and "db_establishment_name".
      Here is a sample:

      db_establishment_id(pk) db_establishment_name
      ---------------------------------------------
      1 The black frog
      2 The king's head
      3 McDonalds
      


      *Second table, called "categories", contains two fields "db_category_id" and "db_category_name"
      Here is a sample:
      db_category_id(pk) db_category_name
      -----------------------------------
      1 restaurant
      2 pub
      



      *Third table, called "establishments_qualifiers", contains two fields "db_establishment_id" and "db_id_category"
      Here is a sample:
      db_establishment_id(pk,fk) db_category_id(pk,fk)
      --------------------------------------
      1 2
      2 2
      2 1
      3 1
      


      *Fourth table, called "visitors_comments", contains two fields "db_establishment_id" and "db_comment"
      Here is a sample:

      db_establishment_id(pk) db_comment
      -----------------------------------
      2 nice pub
      3 cheap food
      3 yok!
      


      My question is as follows: does one need four ejbs or can I have a single ejb here? (I'd rather have one). Ideally I'd like ONE ejb as follows:

      -int establishement_id
      -String establishment_name
      -List categories
      -List comments
      


      How can I have a single ejb with the variables as above? Do I need BMP or CMP?

      Thanks in advance and sorry for the length of my post,

      Julien Martin.


        • 1. Re: Beginner needs help with modelisation issue
          sesques

          Hi Julien,

          My suggested Approach:
          1. First of all decide do you require EJB or not?
          if yes then..
          You have 3 options for data access in j2ee.
          1. CMP
          2. BMP
          3. Pure JDBC calls.

          CMP:
          CMP entity beans can span only a single database table. With the introduction of the EJB 2.0 standard, you can use CMR fields (Container Managed Relationships). A CMR allows a CMP entity bean to maintain a "relationship" to other CMP beans as long as these relationships are represented in the underlying database as foreign keys. CMR allows also relation tables (such as your establishments_qualifiers table). The CMP approach gives you 3 entity beans (establishments, categories and visitors_comments) with 2 relationships (one with a relation table).

          BMP : With BMP, you can have a single entity bean to span your tables. But all the persistence will be managed by you. This is a tiresome, repetitive, and error-prone job, and it often sacrifices portability for the sake of performance.

          JDBC calls : Write a session bean with pure JDBC calls allows you also to have a single bean span to your tables. Same opinion as BMP's.

          Another solution will be using 3 CMP entity beans (as described above) , and one BMP entity bean which fields are the 3 other beans. In this case, the persistence will be managed by the container and you can use your tables through a single BMP bean.

          Good luck


          • 2. Beginner needs help with modelisation issue
            balteo

            Sesques,
            Thanks a lot for your lengthy reply!
            Julien.

            • 3. Re: Beginner needs help with modelisation issue
              triathlon98

              You could use a framework for this kind of thing.

              Using Uni-d, you would define one table for this. The framework will then generate for your three CMP beans and session facade for you.

              Problem is that Uni-d currently completey lacks documentation... Will have to work on that.

              Joachim