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 <[EMAIL PROTECTED]> wrote:
Can you post the selects that you're seeing and the domain model?

Thanks,

-Patrick

On 7/24/07, Christian Defoy <[EMAIL PROTECTED]> 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

Reply via email to