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;








0















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










share|improve this question



















  • 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

















0















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










share|improve this question



















  • 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













0












0








0








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










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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. 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












  • 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







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












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
);



);













draft saved

draft discarded


















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















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현