[英]Getting data from multiple tables without foreign keys in JPA 2.0
I've been stumbling upon followig issue for a couple of days now nad I can't make it to work. 我已经在追随问题上徘徊了两天,而我无法使其正常工作。 Here is the problem.
这是问题所在。 I have four tables (A, B, C, D) which are not related to eachother via any kind of foreign key.
我有四个表(A,B,C,D),它们通过任何一种外键都不相互关联。 Hovewer, they do have a column called, let's say, 'superId'.
但是,他们确实有一个名为“ superId”的列。
The task is to take all the records from the A table, find records from the other ones with matching 'superId' (if they exist) and return them via JPA's constructor expression. 任务是从A表中获取所有记录,从其他具有匹配的“ superId”(如果存在)的记录中查找,并通过JPA的构造函数表达式返回它们。
About JOINs. 关于JOIN。 Since the tables have no relations, I can't do a left JOIN (or any other JOINs).
由于这些表没有关系,因此我无法进行左联接(或任何其他联接)。
I tried to use MULTISELECT with a success, but it only works if I do an implicit joins with 'a.superId = b.superId'. 我尝试成功使用MULTISELECT,但是只有当我使用'a.superId = b.superId'进行隐式联接时,它才有效。 This causes problems, since the three tables might not have matching records which will make the query to return empty set.
这会导致问题,因为三个表可能没有匹配的记录,这会使查询返回空集。 This won't fly.
这不会飞。
I have no other ideas, and this is crucial for my project to work. 我没有其他想法,这对我的项目至关重要。 Please forgive me simple description of an issue - sending from my mobile.
请原谅我一个问题的简单说明-通过手机发送。
You absolutely do not require the presence of a foreign key relationship to perform an arbitrary query in JPA2. 您绝对不需要外键关系来执行JPA2中的任意查询。
You can't "follow" a parent/child relationship, so you can't do your usual parentObject.childObject
thing. 您无法“遵循”父/子关系,因此无法执行通常的
parentObject.childObject
。 You must instead use the Criteria API, or HQL, to construct a join. 您必须改为使用Criteria API或HQL来构建联接。
See: 看到:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.