openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin Sutter" <kwsut...@gmail.com>
Subject Re: Multiple selects when using entityManager.find()
Date Wed, 25 Jul 2007 15:40:04 GMT
I agree (being the owner of OPENJPA-281)...  I have a patch almost ready for
this, but I've found a few edge cases that still need to resolved...

Kevin

On 7/24/07, Craig L Russell <Craig.Russell@sun.com> wrote:
>
> This sounds a lot like https://issues.apache.org/jira/browse/OPENJPA-281
>
> Craig
>
> On Jul 24, 2007, at 1:27 PM, Christian Defoy wrote:
>
> > Oups! I forgot to include it:
> >
> > public enum ShapeTypes
> > {
> >    CIRCLE,
> >    SQUARE,
> >    TRIANGLE,
> >    RECTANGLE;
> > }
> >
> >
> > On 7/24/07, Patrick Linskey <plinskey@gmail.com> wrote:
> >> > Playing around a bit with those classes, I found that if I mark
> >> > attribute Shape.type as EAGER, both techniques produce only one
> >> select
> >> > statement...
> >>
> >> And ShapeTypes is an enum?
> >>
> >> -Patrick
> >>
> >> On 7/24/07, Christian Defoy <christian.defoy@gmail.com> wrote:
> >> > Hi Patrick,
> >> >
> >> > I have two classes.  I stripped the accessors and mutators to
> >> shrink
> >> > them a bit (I am unsure if attachments get stripped or not).
> >> >
> >> > @Entity
> >> > @Table(name="SHAPE")
> >> > public class Shape
> >> > {
> >> >     @Column(name="shape_id")
> >> >     @Id
> >> >     @GeneratedValue(strategy=GenerationType.IDENTITY)
> >> >     private int id;
> >> >
> >> >     @Column( name="type_id" )
> >> >     private ShapeTypes type;
> >> >
> >> >     @OneToOne( mappedBy="parent", cascade=CascadeType.ALL,
> >> > fetch=FetchType.EAGER )
> >> >     private Attachment attachment;
> >> > }
> >> >
> >> > @Entity
> >> > @Table( name="attach" )
> >> > public class Attachment
> >> > {
> >> >     @Id
> >> >     @GeneratedValue( strategy=GenerationType.IDENTITY )
> >> >     @Column( name="attach_id" )
> >> >     private int id;
> >> >
> >> >     @OneToOne( cascade=CascadeType.ALL, fetch=FetchType.LAZY )
> >> >     @Column( name="shape_id" )
> >> >     private Shape parent;
> >> >
> >> >     private String value;
> >> > }
> >> >
> >> > When I use the find() method, I see the following selects:
> >> >
> >> > SELECT t0.SHAPE_ID FROM SHAPE t0 WHERE t0.SHAPE_ID = ? [params=
> >> (int) 16]
> >> > SELECT t0.ATTACH_ID, t0.SHAPE_ID, t0.VALUE FROM ATTACH t0 WHERE
> >> > t0.SHAPE_ID = ? [params=(int) 16]
> >> >
> >> > When I use a JPQL query, I get the following select:
> >> >
> >> > SELECT t0.SHAPE_ID, t1.ATTACH_ID, t1.SHAPE_ID, t1.VALUE FROM
> >> SHAPE t0
> >> > LEFT OUTER JOIN ATTACH t1 ON t0.SHAPE_ID = t1.SHAPE_ID WHERE
> >> > (t0.SHAPE_ID = ?) [params=(int) 16]
> >> >
> >> > Playing around a bit with those classes, I found that if I mark
> >> > attribute Shape.type as EAGER, both techniques produce only one
> >> select
> >> > statement...
> >> >
> >> > Thanks,
> >> >
> >> > Christian
> >> >
> >> >
> >> > On 7/24/07, Patrick Linskey <plinskey@gmail.com> wrote:
> >> > > Can you post the selects that you're seeing and the domain model?
> >> > >
> >> > > Thanks,
> >> > >
> >> > > -Patrick
> >> > >
> >> > > On 7/24/07, Christian Defoy <christian.defoy@gmail.com> wrote:
> >> > > > Hello,
> >> > > >
> >> > > > I just noticed that if I call entityManager.find() to
> >> retrieve an
> >> > > > object, many select statements (one per relation) are
> >> generated even
> >> > > > though the relations are marked as FetchType.EAGER.
> >> > > >
> >> > > > If I use a JPQL query instead, only one select statement is
> >> generated.
> >> > > >  The JPQL looks like this: "SELECT s FROM Shape s WHERE s.id
> >> = :id"
> >> > > >
> >> > > > Is that normal? Is there some configuration property that I
> >> can change?
> >> > > >
> >> > > > Thanks in advance!
> >> > > >
> >> > > > Christian
> >> > > >
> >> > >
> >> > >
> >> > > --
> >> > > Patrick Linskey
> >> > > 202 669 5907
> >> > >
> >> >
> >>
> >>
> >> --
> >> Patrick Linskey
> >> 202 669 5907
> >>
>
> Craig Russell
> Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
> 408 276-5638 mailto:Craig.Russell@sun.com
> P.S. A good JDO? O, Gasp!
>
>
>

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