[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[eclipselink-users] More info
|
I believe I found the 'magic'.
Stepping through the debugger, em.createQuery("select e from Order
e").getResultList() is returning a vector of orders. Each order's
orderlines property is an uninitialized
'org.eclipse.persistence.indirection.IndirectList', which contains an
'UnitOfWorkQueryValueHolder' property, which from the Javadoc '...wraps a
database-stored object and implements behavior to access it..'
So I stripped everything down (no DAOs, factories, providers, etc) and
created a standalone testcase and ran it. After I clear(), close() and set
to null both the em and emf, when I access a LAZY property, Eclipselink
connects to my database and runs the required queries.
Following is the test:
@SuppressWarnings("unchecked")
@Test
public void testNullEMF() throws Exception {
showEMinfo("testNullEMF Starting");
Query qry = em.createQuery("select e from Order e");
qry.setHint(QueryHints.BATCH, "e.orderlines.product.vendor");
List<Order> orders = qry.getResultList();
showEMinfo("Got List");
em.clear();
em.close();
em=null;
emf.close();
emf=null;
showEMinfo("'after destroyed'");
spew(orders);
showEMinfo("testNullEMF Completed");
}
void showEMinfo(String from){
StringBuilder sb = new StringBuilder(from);
sb.append(", EMF: ").append((emf==null ? "NULL" : "okay"));
sb.append(", open? ").append((emf==null ? "N/A" : emf.isOpen()));
sb.append("; EM: ").append((em==null ? "NULL" : "okay"));
sb.append(", open? ").append((em==null ? "N/A" : em.isOpen()));
sb.append(", TrxActive? ").append((em==null ? "N/A" :
em.getTransaction().isActive()));
System.out.println(sb.toString());
}
void spew(List<Order> orders){
showEMinfo("orderSpew Starting");
for(Order ord : orders){
System.out.println(String.format("OrderId %d LineId %d ProductId %d
VendorName %s",
ord.getId(), ord.getOrderlines().get(0).getId(),
ord.getOrderlines().get(0).getProduct().getId(),
ord.getOrderlines().get(0).getProduct().getVendor().getName()
));
}
showEMinfo("orderSpew Completed");
}
And here is the output:
testNullEMF Starting, EMF: okay, open? true; EM: okay, open? true,
TrxActive? false
[EL Fine]: 2009-08-29
14:48:30.906--ServerSession(25292276)--Connection(4890830)--Thread(Thread[main,5,main])--SELECT
ID, NAME FROM orderhdr
Got List, EMF: okay, open? true; EM: okay, open? true, TrxActive? false
[EL Config]: 2009-08-29
14:48:30.984--ServerSession(25292276)--Connection(4890830)--Thread(Thread[main,5,main])--disconnect
[EL Info]: 2009-08-29
14:48:30.984--ServerSession(25292276)--Thread(Thread[main,5,main])--file:/C:/EclipseGalileoBase/ELink_sample/build/classes/-daosample
logout successful
[EL Config]: 2009-08-29
14:48:30.984--ServerSession(25292276)--Connection(29887233)--Thread(Thread[main,5,main])--disconnect
[EL Config]: 2009-08-29
14:48:30.984--ServerSession(25292276)--Connection(26171428)--Thread(Thread[main,5,main])--disconnect
'after destroyed', EMF: NULL, open? N/A; EM: NULL, open? N/A, TrxActive? N/A
orderSpew Starting, EMF: NULL, open? N/A; EM: NULL, open? N/A, TrxActive?
N/A
[EL Config]: 2009-08-29
14:48:30.984--ServerSession(25292276)--Connection(23738549)--Thread(Thread[main,5,main])--connecting(DatabaseLogin(
platform=>PostgreSQLPlatform
user name=> "postgres"
datasource URL=> "jdbc:postgresql:stuff"
))
[EL Config]: 2009-08-29
14:48:31.046--ServerSession(25292276)--Connection(11601738)--Thread(Thread[main,5,main])--Connected:
jdbc:postgresql:stuff
User: postgres
Database: PostgreSQL Version: 8.3.1
Driver: PostgreSQL Native Driver Version: PostgreSQL 8.3 JDBC3 with SSL
(build 603)
[EL Fine]: 2009-08-29
14:48:31.046--ServerSession(25292276)--Connection(11601738)--Thread(Thread[main,5,main])--SELECT
t0.ID, t0.COMMENT, t0.prodid, t0.orderid FROM orderline t0, orderhdr t1
WHERE (t0.orderid = t1.ID)
[EL Fine]: 2009-08-29
14:48:31.062--ServerSession(25292276)--Connection(11601738)--Thread(Thread[main,5,main])--SELECT
t0.ID, t0.NAME, t0.vendorid FROM product t0, orderhdr t2, orderline t1 WHERE
((t0.ID = t1.prodid) AND (t1.orderid = t2.ID))
[EL Fine]: 2009-08-29
14:48:31.062--ServerSession(25292276)--Connection(11601738)--Thread(Thread[main,5,main])--SELECT
t0.ID, t0.NAME FROM orderhdr t3, orderline t2, product t1, vendor t0 WHERE
((t0.ID = t1.vendorid) AND ((t1.ID = t2.prodid) AND (t2.orderid = t3.ID)))
OrderId 1952 LineId 1907 ProductId 2007 VendorName SomeTestData_2
OrderId 1953 LineId 1908 ProductId 2002 VendorName SomeTestData_1
OrderId 1954 LineId 1916 ProductId 2004 VendorName SomeTestData_1
OrderId 1955 LineId 1925 ProductId 2007 VendorName SomeTestData_2
orderSpew Completed, EMF: NULL, open? N/A; EM: NULL, open? N/A, TrxActive?
N/A
testNullEMF Completed, EMF: NULL, open? N/A; EM: NULL, open? N/A, TrxActive?
N/A
--
View this message in context: http://www.nabble.com/Session-%27Magic%27-newb-Question-tp25198387p25205446.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.