Last active
April 23, 2016 03:37
-
-
Save thjanssen/effa9e35f7741a83a9a02cf772dc521b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EntityManager em = emf.createEntityManager(); | |
em.getTransaction().begin(); | |
List<Object[]> results = em.createQuery("SELECT p.firstName, p.lastName, n.phoneNumber FROM Person p JOIN PhoneBookEntry n ON p.firstName = n.firstName AND p.lastName = n.lastName").getResultList(); | |
for (Object[] result : results) { | |
log.info(result[0] + " " + result[1] + " - " + result[2]); | |
} | |
em.getTransaction().commit(); | |
em.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
05:36:36,253 DEBUG SQL:92 - select personenti0_.firstName as col_0_0_, personenti0_.lastName as col_1_0_, phonebooke1_.phoneNumber as col_2_0_ from Person personenti0_ inner join PhoneBookEntry phonebooke1_ on (personenti0_.firstName=phonebooke1_.firstName and personenti0_.lastName=phonebooke1_.lastName) | |
05:36:36,267 INFO TestAdHocJoin:60 - John Doe - 555-0101 | |
05:36:36,268 INFO TestAdHocJoin:60 - John Doe - 555-0100 | |
05:36:36,268 INFO TestAdHocJoin:60 - Jane Doe - 555-0123 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EntityManager em = emf.createEntityManager(); | |
em.getTransaction().begin(); | |
List<Object[]> results = em.createQuery("SELECT p.firstName, p.lastName, n.phoneNumber FROM Person p LEFT JOIN PhoneBookEntry n ON p.firstName = n.firstName AND p.lastName = n.lastName").getResultList(); | |
for (Object[] result : results) { | |
log.info(result[0] + " " + result[1] + " - " + result[2]); | |
} | |
em.getTransaction().commit(); | |
em.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
05:37:11,338 DEBUG SQL:92 - select personenti0_.firstName as col_0_0_, personenti0_.lastName as col_1_0_, phonebooke1_.phoneNumber as col_2_0_ from Person personenti0_ left outer join PhoneBookEntry phonebooke1_ on (personenti0_.firstName=phonebooke1_.firstName and personenti0_.lastName=phonebooke1_.lastName) | |
05:37:11,348 INFO TestAdHocJoin:77 - John Doe - 555-0101 | |
05:37:11,348 INFO TestAdHocJoin:77 - John Doe - 555-0100 | |
05:37:11,349 INFO TestAdHocJoin:77 - Jane Doe - 555-0123 | |
05:37:11,349 INFO TestAdHocJoin:77 - Peter Doe - null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EntityManager em = emf.createEntityManager(); | |
em.getTransaction().begin(); | |
List<Object[]> results = em.createQuery("SELECT p.firstName, p.lastName, n.phoneNumber FROM Person p, PhoneBookEntry n WHERE p.firstName = n.firstName AND p.lastName = n.lastName").getResultList(); | |
for (Object[] result : results) { | |
log.info(result[0] + " " + result[1] + " - " + result[2]); | |
} | |
em.getTransaction().commit(); | |
em.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
05:35:05,400 DEBUG SQL:92 - select personenti0_.firstName as col_0_0_, personenti0_.lastName as col_1_0_, phonebooke1_.phoneNumber as col_2_0_ from Person personenti0_ cross join PhoneBookEntry phonebooke1_ where personenti0_.firstName=phonebooke1_.firstName and personenti0_.lastName=phonebooke1_.lastName | |
05:35:05,425 INFO TestAdHocJoin:43 - John Doe - 555-0101 | |
05:35:05,426 INFO TestAdHocJoin:43 - John Doe - 555-0100 | |
05:35:05,426 INFO TestAdHocJoin:43 - Jane Doe - 555-0123 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment