wood burning stoves 2.0*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Question for SCBCD aspirants (and gurus)... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Question for SCBCD aspirants (and gurus)..." Watch "Question for SCBCD aspirants (and gurus)..." New topic
Author

Question for SCBCD aspirants (and gurus)...

Ann Basso
Ranch Hand

Joined: Jul 26, 2007
Posts: 48
I have two tables (and corresponding entities) - Department and Employee where there is a bidirectional one-to-many relationship between them. (One Dept and multiple employees).

Now, dept D1 has employees E1 and E2, while D2 has E3 and E4. (That is, there are two rows D1 and D2 in Dept table and 4 rows E1-E4 in Employee table).

Question - How many number of rows will be returned by the following queries?

1. SELECT d from Employee e INNER JOIN e.departmant d

2. SELECT d from Department d INNER JOIN d.employees e
Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
Tried this out and found:

1. SELECT d from Employee e INNER JOIN e.departmant d

Would return 4 rows.

2. SELECT d from Department d INNER JOIN d.employees e

Would return 2 rows.


Thanks and Regards
Fei Wong
Greenhorn

Joined: Jun 15, 2009
Posts: 11
i was wondering both query select department, why it return different row result?

Thank You
philippe pele
Greenhorn

Joined: May 08, 2011
Posts: 3
pb sql . no jpa
The INNER JOIN keyword return rows when there is at least one match in both tables.
1. select :
because root query == Employee e. ==>in database:e1[inner d1 OK ],e2[inner d1 OK ],e3[inner d2 OK ],e4[inner d2 OK ] . so result d1,d1,d2,d2 ( because select ==d)
2. select :
because root query == Employee d. ==>in database:d1[inner e1 or e2 OK], d2[inner e3 or e4 OK]. so result d1,d2 ( because select ==d)
philippe pele
Greenhorn

Joined: May 08, 2011
Posts: 3
to be clearer. we must imagine that when you send a query to the database. This one creates a virtual table, from the root (employe e).
first : database create root table ( from employe) (then filters the content based on conditional (if any).)
---
e1
---
e2
---
e3
---
e4
second add joins ( remove lines not conforming to the inner)
---
e1 |d1
---
e2| d1
---
e3| d2
---
e4| d2
finally .from the result of the root table, returns the select result .
philippe pele
Greenhorn

Joined: May 08, 2011
Posts: 3
correction :pb sql . no jpa


because, during the examination 310-094/1Z0-898, ​​I had a very very strong sense of deja vu. A word to the wise
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question for SCBCD aspirants (and gurus)...