Page 1 of 1

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

Posted: Wed May 23, 2012 1:53 am
by cosminvacaroiu
Though not the subject of the question, but won't this return multiple results if the customer has multiple orders ?! You know we should have used distinct c.

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

Posted: Fri Sep 05, 2014 10:21 am
by sztgeza
Another question: what if at //line 2 some getters of CustomerOrder are called, which properties are lazily loaded? In this case, these should generate access to the database.

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

Posted: Wed Dec 09, 2015 1:21 pm
by navaare
I think this question can be reconsidered because for loop may have not been fetched after calling getter but only after calling size() on it Specs says that getters should fetch but Hibernate does not follow JPA For me, that was a case for Hibernate (4.3.4) on JBoss 6.4 EAP. Actually none provider follow JPA in 100%

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

Posted: Wed Dec 09, 2015 9:09 pm
by admin
Yes, that is a problem however for the purpose of the exam, we have to go by the spec.
-Paul.

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

Posted: Fri Jul 21, 2017 3:29 pm
by himaiMinh
Though not the subject of the question, but won't this return multiple results if the customer has multiple orders ?! You know we should have used distinct c.
I tried to return a list of result and a single result. Both work. I don't know why. Maybe, it is specific to Hibernate.

Code: Select all

List  cos= new ArrayList();
String qr = "SELECT  co FROM CustOrder co join  co.lineItems li WHERE co.id = 79";     
Query query = em.createQuery(qr);    
 cos =  query.getResultList();   
  for(Object obj :  cos)     {  
      CustOrder co= (CustOrder) obj;       
     System.out.println(co);
}
//output:
salesapp.CustOrder[id=79 customer =Not Loaded items = Not Loaded]
salesapp.CustOrder[id=79 customer =Not Loaded items = Not Loaded]
salesapp.CustOrder[id=79 customer =Not Loaded items = Not Loaded]
salesapp.CustOrder[id=79 customer =Not Loaded items = Not Loaded]
salesapp.CustOrder[id=79 customer =Not Loaded items = Not Loaded]

and

Code: Select all

CustOrder co= null;
String qr = "SELECT  co FROM CustOrder co join  co.lineItems li WHERE co.id = 79";     
Query query = em.createQuery(qr);    
 co =  query.getSingleResult();   
 System.out.println(co);

//output:
salesapp.CustOrder[id=79 customer =Not Loaded items = Not Loaded]