正如标题所说,我想知道这两种方法的区别。
具体来说,我想知道它们之间的区别:
join(String arg) 和 joinSet(String arg)
因为我可以使用 join(String arg) 即使属性是一个集合,但不是相反,即对一个属性使用 joinSet(String arg)不是集合。
谢谢。
最佳答案
join 方法用于在单个属性上创建内部联接,即一对一关系。
/*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);
虽然 joinSet 方法用于为一组属性创建内部连接,即一对多关系。
/*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);
但是,如果您查看方法的返回类型,join 返回类型 Join,而 joinSet 返回类型 SetJoin,它实现了 Join。这意味着实现应用程序完全有可能放入一些逻辑来检测您是否正在尝试加入一个集合或单个属性,并在必要时将流程转发到 joinSet 方法。在不知道您使用的是什么实现的情况下,我真的无法对此发表更多评论。
在 grep 代码上找到的源代码 here
关于java - Join 和 JoinSet 之间的 JPA 区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27985726/