Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA differences between Join and JoinSet

As the title say, I want to know the differences among these two methods.

Specifically I want to know the difference between:

join(String arg) AND joinSet(String arg)

As I can use join(String arg) even if the attribute is a Set, but not the opposite, namely using joinSet(String arg) on an attribute that is not a Set.

Thanks.

like image 917
Gaetano Piazzolla Avatar asked Jan 16 '15 14:01

Gaetano Piazzolla


1 Answers

The join method is used to create an inner join on a single attribute i.e. a one to one relationship.

   /*Create an inner join to the specified single-valued attribute.
    Parameters:
    attribute target of the join
    Returns:
    the resulting join*/
74 
75     <Y> Join<X, Y> More ...join(SingularAttribute<? super X, Y> attribute);

While the method joinSet is used to create an inner join for a set of attribtues, i.e. a one to many relationship.

 /*Create an inner join to the specified Set-valued attribute.
    Parameters:
    attributeName name of the attribute for the target of the join
    Returns:
    the resulting join
    Throws:
    java.lang.IllegalArgumentException if attribute of the given name does not exist*/
182
183    <X, Y> SetJoin<X, Y> More ...joinSet(String attributeName);  

However, if you look at the return types of the methods, join returns type Join and joinSet returns type SetJoin, which implements Join. This means that it would be entirely possible for the implementing application to put in some logic that detects if you are trying to join a set or single attribute and forward the process onto the joinSet method if necessary. Without knownig what implementation you are using, I cant really comment much further on that.

Source code found on grep code here

like image 70
ConMan Avatar answered Oct 01 '22 02:10

ConMan