Hi Walter,
  > The OpenJPA documentation is very spare about it

We are sorry to hear that FetchPlan documentation did not give you a good
picture of their capability. It is unfortunate because it is a powerful
feature of our runtime. 

> Do you have a detailed example? 
We have a large number of tests in this area but I am afraid that we do not
do a good job in explaining it via accessible examples. If you have access
to OpenJPA source code then look for Test*Fetch*.java and you will see lots
of complex tests.

> There is no way to dynamically create a new FetchPlan at runtime?
No. There is.
  EntityManager em = ...;
  FetchPlan plan = OpenJPAPersistence.cast(em).pushFetchPlan();

> I have to declare FetchGroup by annotations first in order to use the
> FetchPlan feature?
You can declare named groups in annotations. But you can as well create them
programmatically at runtime. Once you create a new one at runtime, then the
API methods listed in the manual, helps you to customize which fields you
want to access in that plan.

> what exactly do I get? My entity with the two fields only? My entity with
> two fields filled and the remains initialized to default values?  
You get your entity with two fields loaded. The other fields are *not*
loaded. If you access those other fields within a transaction, OpenJPA will
go and fetch them from database. If you access them in a remte process, then
they will normally return default values, but you can prohibit access to any
unloaded fields via configuration.   

> Are they initialized with "null" if they are not defined in my custom
> FetchGroup? 
See above.
http://openjpa.apache.org/builds/apache-openjpa-1.2.3-SNAPSHOT/docs/javadoc/org/apache/openjpa/persistence/OpenJPAEntityManager.html#pushFetchPlan()


[1]
http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_fetch

-----
Pinaki Poddar
Chair, Apache OpenJPA Project
--
View this message in context: 
http://openjpa.208410.n2.nabble.com/Best-practice-Using-fetch-groups-or-a-simple-DTO-tp6598057p6603239.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to