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

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
ericrlessa
Posts: 5
Joined: Thu Oct 17, 2013 9:26 pm
Contact:

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

Post 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

admin
Site Admin
Posts: 8941
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

ioan.b
Posts: 3
Joined: Sun Nov 30, 2014 5:00 am
Contact:

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

Post 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

romsky
Posts: 39
Joined: Thu Jan 29, 2015 4:49 pm
Contact:

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

Post 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 ?

Rollebol
Posts: 5
Joined: Tue Jan 12, 2016 12:47 pm
Contact:

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

Post 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!

admin
Site Admin
Posts: 8941
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

Rollebol
Posts: 5
Joined: Tue Jan 12, 2016 12:47 pm
Contact:

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

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

admin
Site Admin
Posts: 8941
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest