primary key - modulling problem


EJB design: primary key - modulling problem

  1. primary key - modulling problem (3 messages)

    Hi All,

      I use erwin for data modelling. I tried to use EJB CMP 2.0 to implements by database tables. I ran into this design problems and i guess i am awefully stuck.

    Consider this scenario,

    Employee {

    Department {

    As per my requirement, each employee should be belonging to a department. so there exists a identifying relationship between the employee and department and the deptId is carried over to the employee table as part of the primary key.

    (.)Now in the employee bean, is the deptId a CMP field or a CMR field? where will i set my primary key - in ejbCreate or in ejbPostCreate?
    (.)what will my primary key class contain? two Integer Fields? or one integer field and one field of type local Remote interface to Department bean?
    (.) how will my findByPrimaryKey work?

    Any help will be greatly appreciated.


    Threaded Messages (3)

  2. primary key - modulling problem[ Go to top ]

    Use a Primary Key class for the composite primary key in the employee bean and Integer type for your department bean.
  3. primary key - modulling problem[ Go to top ]

    thanks for the help,

    i too thought of the same approach. but this question remains. what is the dept Id? cmp field or cmr field? in abstract xml schema?

  4. primary key - modulling problem[ Go to top ]

    Hmm, employeeId is not unique... Peculiar requirement.

    Anyway, I would leave aside data modelling and go for O2R mapping. Just adding oIDs would solve the problem (that's what they are for):

    Department (oID(pk), DeptId,...)
    Employee (oID(pk),DeptOID(fk),EmployeeId,...)

    Set unique contraint on DeptOID+EmployeeId or better yet, check it as a business rule.

    Now, DeptOID is surely a CMR field.