As long as you are inside a transaction, the fields are fetched as you access
them -- irrespective of whether they are in the fetch plan or not. Let us
take a concrete example.
Consider an entity X with three fields id and a,b.c (whether they are
single- or multi-valued is not relevant in this context).
1: em.getTransaction().begin();
2: FetchPlan plan = em.getFetchPlan();
3: plan.addField("a");
4: plan.addField("b");
5: X x = em.find(X.class, 1234);
// The line above will cause OpenJPA to issue a SQL and fetch field id,
a and b.
// So at this point X will have field id=1234, and field a and b
populated while c == null.
6: C c = x.getC();
// This will cause OpenJPA to issue a separate SQL query to fetch the
value of C.
// Because the call is made inside an active transaction.
// even if c was a basic field of say type int or String
7: em.getTransaction().commit();
8: em.close()
Had the the transaction been committed after line 5, the instance x will
become "unmanaged".
The state of x after the transaction has ended will only contain value for
id,a,b but not c. If x.getC() is called, it will return a null -- because at
that point there is no connection to database anymore to fetch the data for
C.
-----
Pinaki
--
View this message in context:
http://openjpa.208410.n2.nabble.com/Fetch-Plan-ands-collections-mapped-tp5321552p5323453.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.