About Question enthuware.oce-jpad.v6.2.463 :
Moderator: admin
About Question enthuware.oce-jpad.v6.2.463 :
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.
-
- Posts: 4
- Joined: Thu Sep 04, 2014 2:32 pm
- Contact:
About Question enthuware.oce-jpad.v6.2.463 :
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.
-
- Posts: 6
- Joined: Thu Jan 01, 2015 2:27 pm
- Contact:
Re: About Question enthuware.oce-jpad.v6.2.463 :
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%
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-jpad.v6.2.463 :
Yes, that is a problem however for the purpose of the exam, we have to go by the spec.
-Paul.
-Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 358
- Joined: Fri Nov 29, 2013 8:26 pm
- Contact:
Re: About Question enthuware.oce-jpad.v6.2.463 :
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.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.
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]
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]
Who is online
Users browsing this forum: No registered users and 110 guests