Sorry, I spoke too soon. My test case actually runs fine. The following
listings are my TblAmdCtl.java, TblAmdDes.java and TestQuerySQLCache. Could you
attach your test case to reproduce this problem in the JIRA? Thanks!
(1) TblAmdCtl.java
@Entity
public class TblAmdctl {
@OneToMany(mappedBy="tblAmdctl",fetch = FetchType.EAGER,cascade = {
CascadeType.PERSIST,CascadeType.MERGE})
private Collection<TblAmddes> tblAmddess = new ArrayList<TblAmddes>();
@Id
@Column(name="AMDCTL_ID")
private int AMDCTL_ID;
public void setId(int id) {
this.AMDCTL_ID = id;
}
public int getId() {
return AMDCTL_ID;
}
public Collection getTblAmddes() {
return tblAmddess;
}
public void addTblAmddes(TblAmddes t) {
tblAmddess.add(t);
}
}
(2) TblAmddes.java
@Entity
public class TblAmddes {
@ManyToOne(fetch = FetchType.LAZY,cascade = {
CascadeType.PERSIST,CascadeType.MERGE })
@JoinColumns([EMAIL PROTECTED](name =
"AMDCTL_ID",referencedColumnName="AMDCTL_ID")})
@ForeignKey
private TblAmdctl tblAmdctl;
@Id
private int id;
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public TblAmdctl getTblAmdctl() {
return tblAmdctl;
}
public void setTblAmdctl(TblAmdctl t) {
tblAmdctl = t;
}
}
(3) test case:
public class TestQuerySQLCache {
public static void main (String[] args) {
createObj();
findObj();
}
public static void createObj() {
EntityManager em = Persistence.createEntityManagerFactory("JpaDemo2").
createEntityManager();
EntityTransaction tran = em.getTransaction();
TblAmdctl ctl1 = new TblAmdctl();
ctl1.setId(1);
TblAmddes des1 = new TblAmddes();
des1.setId(1);
des1.setTblAmdctl(ctl1);
TblAmddes des2 = new TblAmddes();
des2.setId(2);
des2.setTblAmdctl(ctl1);
ctl1.addTblAmddes(des1);
ctl1.addTblAmddes(des2);
TblAmdctl ctl2 = new TblAmdctl();
ctl2.setId(2);
TblAmddes des3 = new TblAmddes();
des3.setId(3);
des3.setTblAmdctl(ctl2);
TblAmddes des4 = new TblAmddes();
des4.setId(4);
des4.setTblAmdctl(ctl2);
ctl2.addTblAmddes(des3);
ctl2.addTblAmddes(des4);
tran.begin();
em.persist(ctl1);
em.persist(ctl2);
em.persist(des1);
em.persist(des2);
em.persist(des3);
em.persist(des4);
em.flush();
tran.commit();
}
public static void findObj() {
EntityManager em = Persistence.createEntityManagerFactory("JpaDemo2").
createEntityManager();
EntityTransaction tran = em.getTransaction();
TblAmdctl ctl1 = em.find(TblAmdctl.class, 1);
Collection<TblAmddes> dess1 = ctl1.getTblAmddes();
for (TblAmddes des : dess1)
System.out.println("des id = " + des.getId());
TblAmdctl ctl2 = em.find(TblAmdctl.class, 2);
Collection<TblAmddes> dess2 = ctl2.getTblAmddes();
for (TblAmddes des : dess2)
System.out.println("des id = " + des.getId());
}
}
--- On Fri, 9/19/08, Fay Wang <[EMAIL PROTECTED]> wrote:
> From: Fay Wang <[EMAIL PROTECTED]>
> Subject: Re: OpenJPA 1.2.0 Bug on FetchType.EAGER
> To: [email protected]
> Date: Friday, September 19, 2008, 9:14 AM
> Hi,
> I can reproduce this problem. Please open a JIRA for
> this problem. Thanks!
>
> -Fay
>
>
> --- On Fri, 9/19/08, egoosen
> <[EMAIL PROTECTED]> wrote:
>
> > From: egoosen <[EMAIL PROTECTED]>
> > Subject: OpenJPA 1.2.0 Bug on FetchType.EAGER
> > To: [email protected]
> > Date: Friday, September 19, 2008, 12:49 AM
> > I'm experiencing a strange bug in 1.2.0, on an
> eager
> > loaded one to many
> > relationship.
> > The first time I run the code, openJPA retrieves the
> parent
> > entity and eager
> > fetches the CORRECT child entities.
> > The second time around, it fetches the parent entity
> and
> > fetches the
> > INCORRECT child entities (specifically, it fetches the
> > child entities of the
> > parent entity in the previous query).
> >
> > Here's the SQL to illustrate:
> > First run:
> > SELECT t0.AMDCTL_ID, t0.VRS_NBR, t0.AMDSEQ_CDE,
> > t0.DPLORD_NBR, t0.FND_CDE,
> > t0.RSL_DTE FROM EBSTATUS.TBL_AMDCTL t0 WHERE
> t0.FND_CDE = ?
> >
> > [params=(String) 0000001]
> > SELECT t0.AMDCTL_ID, t1.AMDDES_ID, t1.VRS_NBR,
> t1.AMD_DES,
> > t1.AMDCTL_ID,
> > t1.EFC_DTE FROM EBSTATUS.TBL_AMDCTL t0 INNER JOIN
> > EBSTATUS.TBL_AMDDES t1 ON
> > t0.AMDCTL_ID = t1.AMDCTL_ID WHERE t0.FND_CDE = ? ORDER
> BY
> > t0.AMDCTL_ID ASC
> > [params=(String) 0000001]
> >
> > Second run:
> > SELECT t0.AMDCTL_ID, t0.VRS_NBR, t0.AMDSEQ_CDE,
> > t0.DPLORD_NBR, t0.FND_CDE,
> > t0.RSL_DTE FROM EBSTATUS.TBL_AMDCTL t0 WHERE
> t0.FND_CDE = ?
> >
> > [params=(String) 0001001]
> > SELECT t0.AMDCTL_ID, t1.AMDDES_ID, t1.VRS_NBR,
> t1.AMD_DES,
> > t1.AMDCTL_ID,
> > t1.EFC_DTE FROM EBSTATUS.TBL_AMDCTL t0 INNER JOIN
> > EBSTATUS.TBL_AMDDES t1 ON
> > t0.AMDCTL_ID = t1.AMDCTL_ID WHERE t0.FND_CDE = ? ORDER
> BY
> > t0.AMDCTL_ID ASC
> > [params=(String) 0000001]
> >
> > Somehow its caching the second query, even though
> I've
> > turned off the
> > DataCache and QueryCache.
> >
> > I've had to revert back to OpenJPA 1.1.0.
> >
> > Here's my mappings:
> > TblAmdctl.java
> > @OneToMany(mappedBy="tblAmdctl",fetch =
> > FetchType.EAGER,cascade = {
> > CascadeType.PERSIST,CascadeType.MERGE})
> > private Collection<TblAmddes> tblAmddess = new
> > ArrayList<TblAmddes>();
> >
> > TblAmddes.java
> > @ManyToOne(fetch = FetchType.LAZY,cascade = {
> > CascadeType.PERSIST,CascadeType.MERGE })
> > @JoinColumns([EMAIL PROTECTED](name =
> >
> "AMDCTL_ID",referencedColumnName="AMDCTL_ID")})
> >
> > @ForeignKey
> > private TblAmdctl tblAmdctl;
> >
> > --
> > View this message in context:
> >
> http://n2.nabble.com/OpenJPA-1.2.0-Bug-on-FetchType.EAGER-tp1100274p1100274.html
> > Sent from the OpenJPA Users mailing list archive at
> > Nabble.com.