How to retrieve records based on multiple columns using CMR?

Discussions

EJB programming & troubleshooting: How to retrieve records based on multiple columns using CMR?

  1. I have three tables namely Project,Course & Students. The Project & Course having pk-field prj_id & course_id respectively which is having a foreign key mapping with Students table. These tables formed the 3 different entitiy beans. I have used CMR (Container Managed Relationships) to get the values from the table Students. i.e. getStudents() method has been defined in Project & Course Entity Beans to get the Students based on either the Project Id or Course Id. These method is returning a Collection.

    Now I would like to find out the Students based on BOTH Project Id & Course Id entered by user. Currently the possible way which I can see is that to get the two different Collection , one is from Project Entity Bean by Project Id & other is from Course Entity Bean by Course Id and then compare both these collections to get the required the Students. With this approach, it increases the database calls as it has to get the Students by project id and then by course id.

    Is this the right approach? and is there any other alternatives which will reduce the database calls?

    Please suggest. Thanks in advance.
  2. If u only want to give a view ..then why do not use the simple JDBC and SQl ,....direct access will make that fast.
    else if u want to manipulate that entity then i will let u know..

    hope this help