You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by David Wisneski <wi...@gmail.com> on 2007/02/15 00:26:39 UTC
extraneous joins OPENJPA-134
Hi Patrick or Abe,
I was wondering if any of you have noticed the following problem. (
this is written up as OPENJPA-134). This shows up as a performance
problem in applications when we compare with Hibernate.
If I have a M:1 relationship and I make both sides of the relationship
EAGER in the mapping, OR I do a join fetch of the multi side
relationship, we see an extra join in the generated sql.
Example: I have a Dept -> Emp with inverse Emp->Dept.
If both sides are EAGER in mapping I get the sql
select .. from dept t0 join emp t1 on(...) join dept t2 on (...)
If both sides are LAZY and I do EJB query
select d from Dept d left join fetch d.emps
the generated sql is
select ... from dept t0 left join emp t1 on(...) join dept t2 on(...)
The extra "join dept t2 on(...)" seems to be extraneous and has a
serious impact on performance. Since I already joined Dept with Emp,
there is no need to join it back to the Dept because the Dept->Emp and
Emp->Dept relationships are inverses of the same foreign key.
Have you noticed this same problem? Might you have a quick fix that
you can? Otherwise we will start analyzing to see what might be
causing it.
Re: extraneous joins OPENJPA-134
Posted by Abe White <aw...@bea.com>.
> I've looked at the code and it looks correct to me and tried various
> things like making the inverse LAZY. But it always generating the
> extraneous join. I've attached the entity source code.
>
> The relationship causing problem is
>
> @ManyToOne
> @JoinColumn(name="ACCOUNT_ACCOUNTID")
> private Accountejb2 account2;
ManyToOne is eager by default, so right now both sides are eager.
_______________________________________________________________________
Notice: This email message, together with any attachments, may contain
information of BEA Systems, Inc., its subsidiaries and affiliated
entities, that may be confidential, proprietary, copyrighted and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.
Re: extraneous joins OPENJPA-134
Posted by David Wisneski <wi...@gmail.com>.
I've looked at the code and it looks correct to me and tried various
things like making the inverse LAZY. But it always generating the
extraneous join. I've attached the entity source code.
The relationship causing problem is
@ManyToOne
@JoinColumn(name="ACCOUNT_ACCOUNTID")
private Accountejb2 account2;
and the inverse is
@OneToMany(mappedBy = "account2", fetch=FetchType.EAGER)
private Set<Holdingejb2> holdings2;
The sql generated is
select ... from accountejb t0 join holdingejb t1 on(...) join
account t2 on(...)
The sql is valid sql, but the second join is extranenous. Any help
would be appreciated.
On 2/14/07, Patrick Linskey <pl...@bea.com> wrote:
> What if just one side is eager? Also, is the @OneToMany's mappedBy
> attribute set up correctly?
>
> -Patrick
>
> --
> Patrick Linskey
> BEA Systems, Inc.
>
> _______________________________________________________________________
> Notice: This email message, together with any attachments, may contain
> information of BEA Systems, Inc., its subsidiaries and affiliated
> entities, that may be confidential, proprietary, copyrighted and/or
> legally privileged, and is intended solely for the use of the individual
> or entity named in this message. If you are not the intended recipient,
> and have received this message in error, please immediately return this
> by email and then delete it.
>
> > -----Original Message-----
> > From: David Wisneski [mailto:wisneskid@gmail.com]
> > Sent: Wednesday, February 14, 2007 3:27 PM
> > To: open-jpa-dev
> > Subject: extraneous joins OPENJPA-134
> >
> > Hi Patrick or Abe,
> >
> > I was wondering if any of you have noticed the following problem. (
> > this is written up as OPENJPA-134). This shows up as a performance
> > problem in applications when we compare with Hibernate.
> >
> > If I have a M:1 relationship and I make both sides of the relationship
> > EAGER in the mapping, OR I do a join fetch of the multi side
> > relationship, we see an extra join in the generated sql.
> >
> > Example: I have a Dept -> Emp with inverse Emp->Dept.
> > If both sides are EAGER in mapping I get the sql
> >
> > select .. from dept t0 join emp t1 on(...) join dept t2 on (...)
> >
> > If both sides are LAZY and I do EJB query
> > select d from Dept d left join fetch d.emps
> >
> > the generated sql is
> > select ... from dept t0 left join emp t1 on(...) join dept
> > t2 on(...)
> >
> > The extra "join dept t2 on(...)" seems to be extraneous and has a
> > serious impact on performance. Since I already joined Dept with Emp,
> > there is no need to join it back to the Dept because the Dept->Emp and
> > Emp->Dept relationships are inverses of the same foreign key.
> >
> > Have you noticed this same problem? Might you have a quick fix that
> > you can? Otherwise we will start analyzing to see what might be
> > causing it.
> >
>
RE: extraneous joins OPENJPA-134
Posted by Patrick Linskey <pl...@bea.com>.
What if just one side is eager? Also, is the @OneToMany's mappedBy
attribute set up correctly?
-Patrick
--
Patrick Linskey
BEA Systems, Inc.
_______________________________________________________________________
Notice: This email message, together with any attachments, may contain
information of BEA Systems, Inc., its subsidiaries and affiliated
entities, that may be confidential, proprietary, copyrighted and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.
> -----Original Message-----
> From: David Wisneski [mailto:wisneskid@gmail.com]
> Sent: Wednesday, February 14, 2007 3:27 PM
> To: open-jpa-dev
> Subject: extraneous joins OPENJPA-134
>
> Hi Patrick or Abe,
>
> I was wondering if any of you have noticed the following problem. (
> this is written up as OPENJPA-134). This shows up as a performance
> problem in applications when we compare with Hibernate.
>
> If I have a M:1 relationship and I make both sides of the relationship
> EAGER in the mapping, OR I do a join fetch of the multi side
> relationship, we see an extra join in the generated sql.
>
> Example: I have a Dept -> Emp with inverse Emp->Dept.
> If both sides are EAGER in mapping I get the sql
>
> select .. from dept t0 join emp t1 on(...) join dept t2 on (...)
>
> If both sides are LAZY and I do EJB query
> select d from Dept d left join fetch d.emps
>
> the generated sql is
> select ... from dept t0 left join emp t1 on(...) join dept
> t2 on(...)
>
> The extra "join dept t2 on(...)" seems to be extraneous and has a
> serious impact on performance. Since I already joined Dept with Emp,
> there is no need to join it back to the Dept because the Dept->Emp and
> Emp->Dept relationships are inverses of the same foreign key.
>
> Have you noticed this same problem? Might you have a quick fix that
> you can? Otherwise we will start analyzing to see what might be
> causing it.
>