About Question enthuware.oce-jpad.v6.2.582 :
Moderators: Site Manager, fjwalraven
-
- Posts: 5
- Joined: Thu Oct 17, 2013 9:26 pm
- Contact:
About Question enthuware.oce-jpad.v6.2.582 :
The answer is not corresponding with the question and the explanation.
the intention wouldn't be something like that ?
CriteriaQuery<Presentation> cq = cb.createQuery(Presentation.class); //2
Root<Student> student = cq.from(Student.class); //3
Join<Student, Presentation> presentation = student.join("presentations");//4
Join<Student, Presentation> presentation2 = student.join("presentations");
cq.select(presentation2).distinct(true); //5
cq.where(cb.ge(presentation.<Integer>get("marksObtained"), new Integer(250)));//6
TypedQuery<Presentation> tq = em.createQuery(cq); //6
the intention wouldn't be something like that ?
CriteriaQuery<Presentation> cq = cb.createQuery(Presentation.class); //2
Root<Student> student = cq.from(Student.class); //3
Join<Student, Presentation> presentation = student.join("presentations");//4
Join<Student, Presentation> presentation2 = student.join("presentations");
cq.select(presentation2).distinct(true); //5
cq.where(cb.ge(presentation.<Integer>get("marksObtained"), new Integer(250)));//6
TypedQuery<Presentation> tq = em.createQuery(cq); //6
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-jpad.v6.2.582 :
No, the first three line are joining the Presentation twice already -
First Presentation - CriteriaQuery<Presentation> cq = cb.createQuery(Presentation.class); //2
Presentation joined with Student - Root<Student> student = cq.from(Student.class); //3
(Presentation joined with Student) joined with Presentation again - Join<Student, Presentation> presentation = student.join("presentations");//4
HTH,
Paul.
First Presentation - CriteriaQuery<Presentation> cq = cb.createQuery(Presentation.class); //2
Presentation joined with Student - Root<Student> student = cq.from(Student.class); //3
(Presentation joined with Student) joined with Presentation again - Join<Student, Presentation> presentation = student.join("presentations");//4
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 3
- Joined: Sun Nov 30, 2014 5:00 am
- Contact:
Re: About Question enthuware.oce-jpad.v6.2.582 :
I agree with ericrlessa. The correct answer should be the one stated by him.
The question asks for a query that will return "all the presentations of the those students who have secured at least 250 marks in at least one of their presentations."
The answer currently designated as correct will result in a query that returns only the presentations with marksObtained >250.
So, another join is needed with Presentation.
The following does not create a join:
The question asks for a query that will return "all the presentations of the those students who have secured at least 250 marks in at least one of their presentations."
The answer currently designated as correct will result in a query that returns only the presentations with marksObtained >250.
So, another join is needed with Presentation.
The following does not create a join:
First Presentation - CriteriaQuery<Presentation> cq = cb.createQuery(Presentation.class); //2
-
- Posts: 39
- Joined: Thu Jan 29, 2015 4:49 pm
- Contact:
Re: About Question enthuware.oce-jpad.v6.2.582 :
The JP QL query implemented by Criteria API is very simple:
select p
from student s join s.presentations p
where p.marksObtained>250.
What is the need for that one:
select p2.* from student s inner join presentation p on s.id=p.presenterid inner join presentation p2 on s.id=p.id where p.marksObtained>250 ?
Sorry, what is "the real brainer" here ?
select p
from student s join s.presentations p
where p.marksObtained>250.
What is the need for that one:
select p2.* from student s inner join presentation p on s.id=p.presenterid inner join presentation p2 on s.id=p.id where p.marksObtained>250 ?
Sorry, what is "the real brainer" here ?
-
- Posts: 5
- Joined: Tue Jan 12, 2016 12:47 pm
- Contact:
Re: About Question enthuware.oce-jpad.v6.2.582 :
Hi,
Why hasn't this question been updated?
Clearly, the answer should contain another join of Student with Presentation.
A root is not a join!
Why hasn't this question been updated?
Clearly, the answer should contain another join of Student with Presentation.
That doesn't make any sense.Presentation joined with Student - Root<Student> student = cq.from(Student.class);
A root is not a join!
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-jpad.v6.2.582 :
The given answer is correct. Please read the problem statement carefully - "...which of the following queries will return all the presentations of the those students who have secured at least 250 marks in at least one of their presentations."
Please go through the detailed explanation.
You may also want to try running the code and verify that it is indeed correct.
HTH,
Paul.
Please go through the detailed explanation.
You may also want to try running the code and verify that it is indeed correct.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 5
- Joined: Tue Jan 12, 2016 12:47 pm
- Contact:
Re: About Question enthuware.oce-jpad.v6.2.582 :
Hi Paul,
I'm afraid the given answer is not correct.
You posted the following earlier:
Why would you think that? It doesn't make any sense! A root is not a join!
Of course, I did verify the presumably correct answer, and as I expected, the Criteria Query returned the wrong result! The query posted by ericrlessa gave the expected result.
I'm afraid the given answer is not correct.
You posted the following earlier:
The above is wrong. The first three lines are not joining Presentation twice already!No, the first three line are joining the Presentation twice already -
First Presentation - CriteriaQuery<Presentation> cq = cb.createQuery(Presentation.class); //2
Presentation joined with Student - Root<Student> student = cq.from(Student.class); //3
(Presentation joined with Student) joined with Presentation again - Join<Student, Presentation> presentation = student.join("presentations");//4
HTH,
Paul.
Why would you think that? It doesn't make any sense! A root is not a join!
Of course, I did verify the presumably correct answer, and as I expected, the Criteria Query returned the wrong result! The query posted by ericrlessa gave the expected result.
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-jpad.v6.2.582 :
Very sorry about the mistake. Yes, you are right. Not sure what I was thinking. This has now been updated.
I apologize for the confusion.
-Paul.
I apologize for the confusion.
-Paul.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 26 guests