1 Reply Latest reply on Mar 7, 2003 11:38 AM by jamarkha

    Simple CMP CMR question

    jamarkha

      This will be an elementary question I'm sure but here goes . . .

      In a bidirectional one-to-many relationship (the classic order/line item), what is the best practice in creating this relationship in the client?

      I know I have to set the Order in the LineItem's ejbPostCreate but the type of code below doesn't appear to work. I know my line of thinking is wrong-headed but I can't seem to figure things out.

      Order order = OrderLocalHome.create(OrderValueObject);

      Iterator i = lineItemValueObjectCollection.iterator();
      while(i.hasNext())
      {
      LineItemHome.create((LineItemValueObject) i.next(), order);
      }

      An eternity of gratitude awaits any who can straighten this knucklehead out.

        • 1. 'not null' foreign keys (was: Simple CMP CMR question)
          jamarkha

          >
          > Order order =
          > OrderLocalHome.create(OrderValueObject);
          >
          > Iterator i =
          > tor i = lineItemValueObjectCollection.iterator();
          > while(i.hasNext())
          > {
          > LineItemHome.create((LineItemValueObject)
          > alueObject) i.next(), order);
          > }

          Well, looking at the forums more in-depth, I found my problem. The problem I was facing was the fact that JBoss CMP 2.0 does not support not null foreign keys. In my example above, the LineItem database table had a 'not null' foreign key of order_id (the primary key in the Order database table).

          My transaction was rolling back because my database (PostgreSQL 7.3.2) would not allow the insert into the LineItem database with 'null' as a value for 'order_id'.

          Bringing up another question:

          I saw in another forum post where someone asks is this a 'bug or a feature'. The answer from Dain was 'neither' which is a technically accurate answer. I'm in a development situation where I'm able to alter the database to get rid of the 'not null' constraints on the tables' foreign keys. But I have to think that most others are not. Also, I'm not comfortable leaving the foreign keys as 'null allowed'.

          What is the best answer for this scenario? BMP? Suck it up and hope the spec comes around with an implementable solution?