0 Replies Latest reply on Nov 1, 2002 6:14 PM by Matias Pelenur

    Creating "child" CMP entity beans...

    Matias Pelenur Newbie

      I have a particular scenario and I've been having trouble coming up with a proper implementation using CMP Entity Beans.

      There is a User entity that has a userid (primary key), username, and password.

      Then I want to have a Customer entity that has a firstname, lastname and email and a customerid that references Users(userid). There's a similar Contractor entity that also references Users(userid). That is, a User can be either a Customer and a Contractor, but not none and not both.

      I tried to implement the User and Customer as entity beans using CMP and CMR to define the One-to-One unidirectional relationship. But I have a few questions:

      - Should the Customer have a customerid primary key AND also a User attribute?

      - How should the reference be set up in jbosscmp-jdbc.xml?

      I've tried several ways but I get strange errors... Sometimes JBoss will try to use customerid twice in the insert statements... Also, am I supposed to first create a User, and then create a Customer giving it the correct Userid? Or is JBoss supposed to automatically create a User for me? Or do I create a User in the Customer.ejbCreate() method? I'm confused and couldn't find any examples that deal with this, in particular with bean creation...

      Any help would be much appreciated.