cancel
Showing results for 
Search instead for 
Did you mean: 

How to get data from Two Tables using EJB's

Former Member
0 Kudos

Hi all,

I have one doubt while writing EJB's. I wrote one EJB project containing 2 EntityBeans named FirstEntityBean and SecondEntityBean. FirstEntityBean mapped to Table1 and SecondEntityBean mapped to the Table2 in the Database. There is a field named "LINKFIELD" in both the Tables which will link both the tables.

Now i want to retrieve some rows from both the tables based on the LINKFIELD. So for this i need to write a query using the JOINS in the EJB QL. I wrote the EJB QL in the finder Method of FirstEntityBean. But the return of the finder Method is FirstEntityBean. And i was unable to return the fields which are in the SecondEntityBean. How can i return these fields from the FirstEntityBean finder method. Is there any way for this?

Is Relations Concept is helpful for this requirement?

Thanks in advance,

RAMU.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi VJ,

Yes, Container-Managed-Relationship field have a pair of abstract getter and setter for it, return a reference or a Collection (or Set) to another entity bean.

For example, if there is a Movie Bean and Director Bean. One Movie bean can have only one director, but a director can have zero or many movie beans.

example of EJB-QL is as below:

SELECT m.title FROM MovieSchema m WHERE m.director.directorID=?1

Also, u need to configure <ejb-relation> tag for ejb-relationship-role, multiplicity, relationship-role-source, cmr-field and cascade-delete.

Hope this can help.