CMR and CMF problem

Discussions

EJB programming & troubleshooting: CMR and CMF problem

  1. CMR and CMF problem (5 messages)

      i create a relationship between two cmp-entitybeans, the field in one bean mapps the pk in one table and another field in the other bean mapps the fk in the other table.
    when i use setxxx to set the field mapping the fk in table , It throws the exception "
    javax.ejb.TransactionRolledbackLocalException: EJB Exception: ; nested exception
     is: javax.ejb.EJBException: When a cmp-field and a cmr-field (relationship) are
     mapped to the same column, the setXXX method for the cmp-field may not be calle
    d. The cmp-field is read-only."

    so i cannot set the field mapping the fk in the table .How can i set the field then?

    thanks !

    who can help me !
           

                                               sam

    Threaded Messages (5)

  2. CMR and CMF problem[ Go to top ]


    You have defined 1 Database field XXX as being a CMP field and involved in a CMR relationship. In weblogic at least, you can only set this field over the CMR relationship. So instead of using setXXX, you'll need to use the CMR set method.

    Example:

    1 Teacher - N Students
    The student table would have a teacherID column, and the student bean would have get/setTeacherID, as well as get/setTeacherEJB(). Use setTeacherEJB() and pass it the remote/local interface of a teacher.

    Daniel.
  3. CMR and CMF problem[ Go to top ]

    thanks for your answer

    but setxxxEJB just use bean as input parameter ,so i must get a bean finded to as the input parmamete ?
  4. CMR and CMF problem[ Go to top ]

    another question:

    example:
    1 Teacher- N Sudents
    when i create a relationship ,i can only from the bean which has pk from the bean whick has fk . so i can only create a undirectional relationship from teacher to students ,then only the teacher bean has the CMR students .
    If i want to set the student bean 's field teacherid, i should set the relationship bidirectional.
    isn't it?


    sam
  5. CMR and CMF problem[ Go to top ]


    Hi,

    You now using CMP relationships. You have to forget that there is a database underneath.

    So, yes if you want to have a relationship between 2 beans, then you'll need to have those two beans and use setxxxEJB to create the relationship. You cannot set foreign keys directly.

    I'm not entirely understanding your example. But, If you have the relationship 1 Teacher - N Students then:
    1. Make it bi-directional

    2. Student will have the methods:
    - create(name, etc, TeacherEJB teacher);
    - TeacherEJB getTeacher()
    - setTeacher(TeacherEJB teacher)

    3. Teacher will have the methods:
    - Collection getStudents()
    - setStudents(Collection studentsEJB)
    and maybe (optional)
    - addStudent(StudentEJB student)
    - removeStudent(StudentEJB student)

    and everything will be happy.

    daniel.
  6. CMR and CMF problem[ Go to top ]

    thanks a lot for you answer .

      I come from china ,where are u come from .Can we make a friend ?My email:helinqing at 263 dot net. my yahoo messageid :
    xllforever.