openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nikolas Everett" <nik9...@gmail.com>
Subject Re: Tons of unneeded queries
Date Fri, 02 May 2008 14:14:39 GMT
I did end up changing that from eager to lazy, which fixed my performance
problem, but it still left me confused about why the query is needed in the
first place.  Why can't OpenJPA use the Account object that is already
loaded?  Is there some way to force OpenJPA to do that?

--Nik


On Thu, May 1, 2008 at 5:16 PM, Fay Wang <fyw300@yahoo.com> wrote:

> The sql, SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> t0 INNER JOIN Account t1 ON t0.account_id = t1.id WHERE t0.id = ?, is
> generated because the TimeDependentAccountData tries to populate its eager
> Account field. This sql will not be generated if this field is lazy.
>
> - Fay
>
>
> --- On Thu, 5/1/08, Frederic_Bellier@capgroup.com <
> Frederic_Bellier@capgroup.com> wrote:
>
> > From: Frederic_Bellier@capgroup.com <Frederic_Bellier@capgroup.com>
> > Subject: Re: Tons of unneeded queries
> > To: dev@openjpa.apache.org
> > Cc: dev@openjpa.apache.org
> > Date: Thursday, May 1, 2008, 9:36 AM
> > It seems to me that he should put the lazy on the
> > one-to-many relation and
> > not the many-to-one relation.
> >
> > F
> >
> >
> >
> >
> >
> >              Fay Wang
> >
> >              <fyw300@yahoo.com
> >
> >              >
> >                To
> >
> > dev@openjpa.apache.org
> >
> >             cc
> >              05/01/2008 08:41
> >
> >              AM
> >        Subject
> >                                        Re: Tons of unneeded
> > queries
> >
> >
> >              Please respond to
> >
> >              dev@openjpa.apach
> >
> >                    e.org
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > Hi Nick,
> >     The unneeded queries can be removed if you specify lazy
> > relationship
> > with Account in your TimeDependentAccountData entity as
> > shown below:
> >
> > @Entity
> > public class TimeDependentAccountData {
> >     @Id
> >     @GeneratedValue(strategy=GenerationType.IDENTITY)
> >     private int id;
> >
> >     @ManyToOne(
> >         cascade = {CascadeType.PERSIST},
> >         fetch = FetchType.LAZY,    <====== change from
> > EAGER to LAZY
> >         optional = false
> >         )
> >     private Account account;
> >
> > - Fay
> >
> > --- On Wed, 4/30/08, Nikolas Everett
> > <nik9000@gmail.com> wrote:
> > From: Nikolas Everett <nik9000@gmail.com>
> > Subject: Tons of unneeded queries
> > To: dev@openjpa.apache.org
> > Date: Wednesday, April 30, 2008, 8:00 AM
> >
> > I'm having a problem where one of my dependent objects
> > is fetching the
> > object it is dependent on, even though that dependent
> > object has already
> > fetched.
> >
> >
> > I am using OpenJpa 1.0.2 backed into Postgres 8.2.6.  I
> > have two objects:
> > Account and TimeDependentAccountData.
> >
> >
> > @Entity
> > @Table(uniqueConstraints={@UniqueConstraint(columnNames="uuid")})
> > public class Account {
> >     @Id
> >     @GeneratedValue(strategy=GenerationType.IDENTITY)
> >     private int id;
> >
> >     @OneToMany(cascade={CascadeType.PERSIST,
> > CascadeType.REFRESH,
> > CascadeType.MERGE}, fetch=FetchType.EAGER,
> > mappedBy="account")
> >     @OrderBy("startTime ASC")
> >     private List<TimeDependentAccountData>
> > timeDependentAccountData;
> >
> > ...getters and setters...
> > }
> >
> >
> > Entity
> > public class TimeDependentAccountData {
> >     @Id
> >     @GeneratedValue(strategy=GenerationType.IDENTITY)
> >     private int id;
> >
> >     @ManyToOne(cascade = {CascadeType.PERSIST}, fetch =
> > FetchType.EAGER,
> > optional = false)
> >     private Account account;
> >
> > ...getters and setters...
> > }
> >
> > When I do something like em.createQuery("SELECT a FROM
> > Account")
> > OpenJPA
> > runs the following SQL queries:
> > 2785 SELECT t0.id, t0.uuid FROM Account t0
> > 2797 SELECT t0.id, t1.id, t1.field1, t1.field2, t1.field3,
> > t1.field4 FROM
> > Account t0 INNER JOIN TimeDependentAccountData t1 ON t0.id
> > = t1.account_id
> > ORDER BY t0.id ASC, t1.startTime ASC
> > 115796 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 1
> > 115799 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 2
> > 115800 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 3
> > 115802 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 4
> > 115804 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 5
> > 115805 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 6
> > 115807 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 7
> > 115808 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 8
> > 115810 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 9
> > 115811 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 10
> > 115813 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 11
> > 115814 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 12
> > 115816 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 13
> > 115817 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 14
> > 115819 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 15
> > 115821 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 16
> > 115822 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 17
> > 115824 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 18
> > 115825 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 19
> > 115827 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 20
> > 115828 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 21
> > 115830 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 22
> > 115831 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 23
> > 115833 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 24
> > 115835 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 25
> > 115836 SELECT t1.id, t1.uuid FROM TimeDependentAccountData
> > t0 INNER JOIN
> > Account t1 ON t0.account_id = t1.id WHERE t0.id = ?
> > [params=(int) 26
> > And another 400 or so of these.
> >
> > What can I do to prevent this silliness?
> >
> > Thanks,
> >
> > --Nik
> >
> >
> >
> >
> ____________________________________________________________________________________
> >
> > Be a better friend, newshound, and
> > know-it-all with Yahoo! Mobile.  Try it now.
> > http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
>
>
>
>  ____________________________________________________________________________________
> Be a better friend, newshound, and
> know-it-all with Yahoo! Mobile.  Try it now.
> http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message