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

Moderator: admin

Post Reply
cosminvacaroiu

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

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

sztgeza
Posts: 4
Joined: Thu Sep 04, 2014 2:32 pm
Contact:

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

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

navaare
Posts: 6
Joined: Thu Jan 01, 2015 2:27 pm
Contact:

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

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

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

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

Post by admin »

Yes, that is a problem however for the purpose of the exam, we have to go by the spec.
-Paul.
If you like our products and services, please help us by posting your review here.

himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

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

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

Post Reply

Who is online

Users browsing this forum: No registered users and 31 guests