• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Left Join Example

 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found the following example from "EJB 3 in Action" book.

EJB 3 In Action wrote:



I couldn't understand the usability of this code. It uses an outer join for the u.Category (c), but it didn't use anywhere I doesn't understand the meaning of this code actually.

In addition to that, what is the maning of....

Is it saying that the user id like the first record in the table?

Please someone help me.
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The query returns a user with the given id. The left join is not necessary here,

has the same effect. I would understand it if fetch join was used, which would retrieve the given user and its category, which could be lazy.
If it was an inner join, it would return the given user only if it contained a category.
The 'like ?1' uses a positional parameter.
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Raf, but I have another question:

Raf Szczypiorski wrote:The 'like ?1' uses a positional parameter.


Treimin Clark wrote:
Is it saying that the user id like the first record in the table?

Please someone help me.
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will answer with code:

The code above implies that the id is of type String, as 'like' is only available for String properties. The query returns a list if users whose id is "100" or starts with "100" and has anything after these 3 digits. See JPA specs 4.6.9 for a description of 'like', and 4.6.4.1 for positional parameters.
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Raf!
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Raf.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic