Page 1 of 1

About Question enthuware.oce-jpad.v6.2.582 :

Posted: Tue Oct 29, 2013 7:26 pm
by ericrlessa
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

Re: About Question enthuware.oce-jpad.v6.2.582 :

Posted: Sat Nov 02, 2013 7:39 am
by admin
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.

Re: About Question enthuware.oce-jpad.v6.2.582 :

Posted: Sun Nov 30, 2014 7:05 am
by ioan.b
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:
First Presentation - CriteriaQuery<Presentation> cq = cb.createQuery(Presentation.class); //2

Re: About Question enthuware.oce-jpad.v6.2.582 :

Posted: Tue Sep 22, 2015 11:09 am
by romsky
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 ?

Re: About Question enthuware.oce-jpad.v6.2.582 :

Posted: Tue Jan 12, 2016 12:58 pm
by Rollebol
Hi,

Why hasn't this question been updated?
Clearly, the answer should contain another join of Student with Presentation.
Presentation joined with Student - Root<Student> student = cq.from(Student.class);
That doesn't make any sense.
A root is not a join!

Re: About Question enthuware.oce-jpad.v6.2.582 :

Posted: Tue Jan 12, 2016 9:31 pm
by admin
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.

Re: About Question enthuware.oce-jpad.v6.2.582 :

Posted: Wed Jan 13, 2016 4:23 am
by Rollebol
Hi Paul,

I'm afraid the given answer is not correct.
You posted the following earlier:
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.
The above is wrong. The first three lines are not joining Presentation twice already!
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.

Re: About Question enthuware.oce-jpad.v6.2.582 :

Posted: Wed Jan 13, 2016 5:53 am
by admin
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.