CriteriaBuilder - Join table to itself with complex ONHow to make a CriteriaBuilder join with a custom “on” condition?JPA eager fetch does not joinJava: checked vs unchecked exception explanationHow to make a CriteriaBuilder join with a custom “on” condition?JPA CriteriaBuilder Subquery multiselectHibernate: Multiple condition on LEFT JOIN using a criteriaBuilerStandard query JPA-CriteriaBuilder eclipseLink optimizationJPA CriteriaBuilder left outer join for table with no relations?Inner joining multiple tables using JPA CriteriaBuilderSemi-Join using JPA criteriaBuilderHow to create inner join query using CriteriaBuilder with non primary key columns;
Subtleties of choosing the sequence of tenses in Russian
Does jamais mean always or never in this context?
Are Boeing 737-800’s grounded?
Pulling the rope with one hand is as heavy as with two hands?
Any examples of headwear for races with animal ears?
How to set the font color of quantity objects (Version 11.3 vs version 12)?
Asahi Dry Black beer can
In gnome-terminal only 2 out of 3 zoom keys work
Can fracking help reduce CO2?
Do I have an "anti-research" personality?
How to stop co-workers from teasing me because I know Russian?
When and why did journal article titles become descriptive, rather than creatively allusive?
Find the coordinate of two line segments that are perpendicular
What are the spoon bit of a spoon and fork bit of a fork called?
Why is current rating for multicore cable lower than single core with the same cross section?
Binary Numbers Magic Trick
Transfer over $10k
Does a creature that is immune to a condition still make a saving throw?
Lock in SQL Server and Oracle
Why do TACANs not have a symbol for compulsory reporting?
How to replace the "space symbol" (squat-u) in listings?
Modify locally tikzset
Python "triplet" dictionary?
What is the difference between `a[bc]d` (brackets) and `ab,cd` (braces)?
CriteriaBuilder - Join table to itself with complex ON
How to make a CriteriaBuilder join with a custom “on” condition?JPA eager fetch does not joinJava: checked vs unchecked exception explanationHow to make a CriteriaBuilder join with a custom “on” condition?JPA CriteriaBuilder Subquery multiselectHibernate: Multiple condition on LEFT JOIN using a criteriaBuilerStandard query JPA-CriteriaBuilder eclipseLink optimizationJPA CriteriaBuilder left outer join for table with no relations?Inner joining multiple tables using JPA CriteriaBuilderSemi-Join using JPA criteriaBuilderHow to create inner join query using CriteriaBuilder with non primary key columns;
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have a table called programs
and I want to create a query using CriteriaBuilder
that joins the table to itself as in:
SELECT *
FROM programs p1
LEFT JOIN programs p2
ON p1.name = p2.name AND p1.version < p2.version
So far I have
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Program> cq = cb.createQuery(Program.class);
Root<Program> root = cq.from(Program.class);
Join<Program, Program> programJoin = root.join("name", JoinType.LEFT);
programJoin.on(cb.equal(//I don't know...))
But I'm stuck here, not knowing how to recreate the above SQL ON
condition p1.version < p2.version
java jpa
add a comment |
I have a table called programs
and I want to create a query using CriteriaBuilder
that joins the table to itself as in:
SELECT *
FROM programs p1
LEFT JOIN programs p2
ON p1.name = p2.name AND p1.version < p2.version
So far I have
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Program> cq = cb.createQuery(Program.class);
Root<Program> root = cq.from(Program.class);
Join<Program, Program> programJoin = root.join("name", JoinType.LEFT);
programJoin.on(cb.equal(//I don't know...))
But I'm stuck here, not knowing how to recreate the above SQL ON
condition p1.version < p2.version
java jpa
1
The duplicate in question does not answer my question, as it does not deal with a scenario in which both tables are of the same type
– Wmbuch
Mar 22 at 20:11
Did you try the answer of the other question? What error do you get?
– dur
Mar 23 at 15:00
I'm afraid this is not possible using criteria builder because criteria builder works with your entities model. You would need to have the association to another Program declared in your Program class. Yourroot.join("name", JoinType.LEFT)
won't work neither because it expects the "name" to be property of type Program but it is String. If you used type-safe metamodel (instead of String names of properties) you would get compiler error.
– bambula
Mar 23 at 18:44
add a comment |
I have a table called programs
and I want to create a query using CriteriaBuilder
that joins the table to itself as in:
SELECT *
FROM programs p1
LEFT JOIN programs p2
ON p1.name = p2.name AND p1.version < p2.version
So far I have
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Program> cq = cb.createQuery(Program.class);
Root<Program> root = cq.from(Program.class);
Join<Program, Program> programJoin = root.join("name", JoinType.LEFT);
programJoin.on(cb.equal(//I don't know...))
But I'm stuck here, not knowing how to recreate the above SQL ON
condition p1.version < p2.version
java jpa
I have a table called programs
and I want to create a query using CriteriaBuilder
that joins the table to itself as in:
SELECT *
FROM programs p1
LEFT JOIN programs p2
ON p1.name = p2.name AND p1.version < p2.version
So far I have
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Program> cq = cb.createQuery(Program.class);
Root<Program> root = cq.from(Program.class);
Join<Program, Program> programJoin = root.join("name", JoinType.LEFT);
programJoin.on(cb.equal(//I don't know...))
But I'm stuck here, not knowing how to recreate the above SQL ON
condition p1.version < p2.version
java jpa
java jpa
edited Mar 22 at 19:41
Wmbuch
asked Mar 22 at 19:19
WmbuchWmbuch
389212
389212
1
The duplicate in question does not answer my question, as it does not deal with a scenario in which both tables are of the same type
– Wmbuch
Mar 22 at 20:11
Did you try the answer of the other question? What error do you get?
– dur
Mar 23 at 15:00
I'm afraid this is not possible using criteria builder because criteria builder works with your entities model. You would need to have the association to another Program declared in your Program class. Yourroot.join("name", JoinType.LEFT)
won't work neither because it expects the "name" to be property of type Program but it is String. If you used type-safe metamodel (instead of String names of properties) you would get compiler error.
– bambula
Mar 23 at 18:44
add a comment |
1
The duplicate in question does not answer my question, as it does not deal with a scenario in which both tables are of the same type
– Wmbuch
Mar 22 at 20:11
Did you try the answer of the other question? What error do you get?
– dur
Mar 23 at 15:00
I'm afraid this is not possible using criteria builder because criteria builder works with your entities model. You would need to have the association to another Program declared in your Program class. Yourroot.join("name", JoinType.LEFT)
won't work neither because it expects the "name" to be property of type Program but it is String. If you used type-safe metamodel (instead of String names of properties) you would get compiler error.
– bambula
Mar 23 at 18:44
1
1
The duplicate in question does not answer my question, as it does not deal with a scenario in which both tables are of the same type
– Wmbuch
Mar 22 at 20:11
The duplicate in question does not answer my question, as it does not deal with a scenario in which both tables are of the same type
– Wmbuch
Mar 22 at 20:11
Did you try the answer of the other question? What error do you get?
– dur
Mar 23 at 15:00
Did you try the answer of the other question? What error do you get?
– dur
Mar 23 at 15:00
I'm afraid this is not possible using criteria builder because criteria builder works with your entities model. You would need to have the association to another Program declared in your Program class. Your
root.join("name", JoinType.LEFT)
won't work neither because it expects the "name" to be property of type Program but it is String. If you used type-safe metamodel (instead of String names of properties) you would get compiler error.– bambula
Mar 23 at 18:44
I'm afraid this is not possible using criteria builder because criteria builder works with your entities model. You would need to have the association to another Program declared in your Program class. Your
root.join("name", JoinType.LEFT)
won't work neither because it expects the "name" to be property of type Program but it is String. If you used type-safe metamodel (instead of String names of properties) you would get compiler error.– bambula
Mar 23 at 18:44
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55306471%2fcriteriabuilder-join-table-to-itself-with-complex-on%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55306471%2fcriteriabuilder-join-table-to-itself-with-complex-on%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
The duplicate in question does not answer my question, as it does not deal with a scenario in which both tables are of the same type
– Wmbuch
Mar 22 at 20:11
Did you try the answer of the other question? What error do you get?
– dur
Mar 23 at 15:00
I'm afraid this is not possible using criteria builder because criteria builder works with your entities model. You would need to have the association to another Program declared in your Program class. Your
root.join("name", JoinType.LEFT)
won't work neither because it expects the "name" to be property of type Program but it is String. If you used type-safe metamodel (instead of String names of properties) you would get compiler error.– bambula
Mar 23 at 18:44