Hi Fay,
I'm retrieving a TblFndmst entity by its ID (fndCde), then I'm retrieving a
collection of TblAmdctl entities by calling Tblfndmst.getTblAmdctls (this
lazy loads the entities).
TblAmddes are mapped to TblAmdctl with a FetchType.EAGER, so by lazy loading
the TblAmdctls, the TblAmddes entities are automatically fetched as well.
Here's the mapping on TblFndmst for TblAmdctl:
@OneToMany(mappedBy="tblFndmst",fetch = FetchType.LAZY,cascade = {
CascadeType.PERSIST,CascadeType.MERGE })
private Collection<TblAmdctl> tblAmdctls = new ArrayList<TblAmdctl>();
Hope this answers your question.
Regards,
Enrico
Fay Wang wrote:
>
> Hi Ernico,
>
> Thank you very much for the java classes. With these two java classes
> and the TblFndmst.java/BaseEntity.java that I made up, I am able to
> generate the sql that you reported having problems using the dynamic JPQL
> query:
> select ctl from TblAmdctl ctl where ctl.fndCde = ?1
>
> The push-down SQL are:
> SELECT t0.AMDCTL_ID, t0.VRS_NBR, t0.AMDSEQ_CDE, t0.DPLORD_NBR, t0.FND_CDE,
> t0.RSL_DTE FROM TblAmdctl t0 WHERE (t0.FND_CDE = ?) [params=(String) 7]
>
> SELECT t0.AMDCTL_ID, t1.AMDDES_ID, t1.VRS_NBR, t1.AMD_DES, t1.AMDCTL_ID,
> t1.EFC_DTE FROM TblAmdctl t0 INNER JOIN TblAmddes t1 ON t0.AMDCTL_ID =
> t1.AMDCTL_ID WHERE (t0.FND_CDE = ?) ORDER BY t0.AMDCTL_ID ASC
> [params=(String) 7]
>
> The find TblAmdctl by primary key operation generates very different
> sql (the where clause in findBy should have primary key, ie. t0.AMDCTL_ID
> = ?).
>
> Could you confirm that the error you reported is from findBy operation
> or from the JPQL? If it is from the JPQL, can you post the code snippet?
> Many thanks!
>
> The following is what I do:
> String qryString = "select ctl from TblAmdctl ctl where ctl.fndCde =
> ?1";
>
> - The first round:
> Query qry = em.createQuery(qryString);
> qry.setParameter(1, "7");
> List<TblAmdctl> list = qry.getResultList();
>
> - The second round:
> qry.setParameter(1, "8");
> list = qry.getResultList();
>
> -Fay
>
--
View this message in context:
http://n2.nabble.com/OpenJPA-1.2.0-Bug-on-FetchType.EAGER-tp1100274p1117455.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.