假设我有三个表:
CREATE TABLE "C" (
id bigint NOT NULL,
cc integer,
CONSTRAINT "C_ID" PRIMARY KEY (id)
);
ALTER TABLE "C" OWNER TO ***;
CREATE TABLE "B" (
id bigint NOT NULL,
c_id bigint references "C"(id),
bb integer,
CONSTRAINT "B_ID" PRIMARY KEY (id)
);
ALTER TABLE "B" OWNER TO ***;
CREATE TABLE "A" (
id bigint NOT NULL,
c_id bigint references "C"(id),
aa integer,
CONSTRAINT "A_ID" PRIMARY KEY (id)
);
ALTER TABLE "A" OWNER TO ***;
我需要从表A中选择具有公共外键(c_id)和表B中的行的行。但是,我有以下SQL查询
SELECT "A".aa AS "AA", "B".bb AS "BB", "C".id AS "C_ID"
FROM "A"
INNER JOIN "C" on "C".id = "A".c_id
INNER JOIN "B" on "C".id = "B".c_id;
在Java中
@Entity
class A {
...
@ManyToOne
C cObj;
...
}
@Entity
class B {
..
@ManyToOne
C cObj;
..
}
@Entity
class C {
..
}
所以问题:如何编写等效的Criteria API查询? 感谢。