yes, I agree with you.

I've just read the doc of Hibernate. It sets the FetchType=EAGER  for
relation @ManyToOne and @OneToOne  as default, so we can access the
associated o

You have the ability to either eagerly or lazily fetch associated
entities. The fetch parameter can be set to FetchType.LAZY or
FetchType.EAGER. EAGER will try to use an outer join select to
retrieve the associated object, while LAZY will only trigger a select
when the associated object is accessed for the first time. @OneToMany
and @ManyToMany associations are defaulted to LAZY and @OneToOne and
@ManyToOne are defaulted to EAGER. For more information about static
fetching, check Section 2.4.5.1, “Lazy options and fetching modes”.

The recommanded approach is to use LAZY on all static fetching
definitions and override this choice dynamically through JP-QL. JP-QL
has a fetch keyword that allows you to override laziness when doing a
particular query. This is very useful to improve performance and is
decided on a use case to use case basis.

reference: 
http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/#entity-mapping-association





On Oct 13, 10:03 am, Johannes Schmitt <[email protected]> wrote:
> Hey Alan,
>
> fetch="EAGER" only makes sense if you always want to eagerly fetch this
> relation.
>
> If you just need to eagerly fetch it in this instance, then it is sufficient
> to construct a DQL query where you join the relation "SELECT a,b FROM
> Model:A a LEFT JOIN a.myRelation b" (you can also add such a query to your
> repository).
>
> regards,
> Johannes
>
>
>
>
>
>
>
> On Thu, Oct 13, 2011 at 9:57 AM, Alan Lee <[email protected]> wrote:
> > it was solved by adding EAGER in ManyToOne Annotation, and
> > JMSSerializerBundle will then retrieve the real Entity of Word.
>
> >  @orm\ManyToOne(targetEntity="Myundle\Entity\Word",
> > inversedBy="fliptrackings",  fetch="EAGER"))
>
> > I think for relationship ManyToMany or OneToMany the option
> > fetch="EAGER" could be really bad and causes performance problem, as
> > they load all the entities in the associated collection.  But
> > ManyToOne  should be ok, right?
>
> > On Oct 13, 8:24 am, Johannes Schmitt <[email protected]> wrote:
> > > seehttps://github.com/schmittjoh/JMSSerializerBundle/issues/34
>
> > > regards,
> > > Johannes
>
> > > On Thu, Oct 13, 2011 at 12:01 AM, Alan Lee <[email protected]>
> > wrote:
> > > > thanks, it really works. But I still have a problem when I try to
> > > > serialize a proxy class of an Entity.
>
> > > > e.g.
> > > > Class DIct {
> > > >  protected $words;
> > > > }
>
> > > > Class TestController {
>
> > > >    public function testAction() {
>
> > > >       $word = $dict->getWords()->first(); // $word is here actually a
> > > > proxy class of Word
> > > >       $serializer = $this->get('serializer');
> > > >       return  new Response( $serializer->serialize($word  , 'json'));
>
> > > >    }
> > > > }
>
> > > > It's just an example, my question is how to serialize the proxy class
> > > > $word or could we get the original Word instance from proxy?
>
> > > > On Oct 12, 1:13 pm, Johannes Schmitt <[email protected]> wrote:
> > > > > You can try my bundle:
> >http://github.com/schmittjoh/JMSSerializerBundle
>
> > > > > regards,
> > > > > Johannes
>
> > > > > On Wed, Oct 12, 2011 at 9:14 AM, Alan Lee <[email protected]>
> > > > wrote:
> > > > > > Hello,
>
> > > > > > I'm trying to serialize an Doctrine Entity to json, but my problem
> > is
> > > > > > the GetSetMethodNormalizer  seems not to work well with recursive
> > > > > > Entity.
>
> > > > > > so what's the standard or better solution if I wanna show an Entity
> > in
> > > > > > json format?
>
> > > > > > any comments or ideas are very welcome
>
> > > > > > --
> > > > > > If you want to report a vulnerability issue on symfony, please send
> > it
> > > > to
> > > > > > security at symfony-project.com
>
> > > > > > You received this message because you are subscribed to the Google
> > > > > > Groups "symfony developers" group.
> > > > > > To post to this group, send email to [email protected]
> > > > > > To unsubscribe from this group, send email to
> > > > > > [email protected]
> > > > > > For more options, visit this group at
> > > > > >http://groups.google.com/group/symfony-devs?hl=en
>
> > > > --
> > > > If you want to report a vulnerability issue on symfony, please send it
> > to
> > > > security at symfony-project.com
>
> > > > You received this message because you are subscribed to the Google
> > > > Groups "symfony developers" group.
> > > > To post to this group, send email to [email protected]
> > > > To unsubscribe from this group, send email to
> > > > [email protected]
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/symfony-devs?hl=en
>
> > --
> > If you want to report a vulnerability issue on symfony, please send it to
> > security at symfony-project.com
>
> > You received this message because you are subscribed to the Google
> > Groups "symfony developers" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]
> > For more options, visit this group at
> >http://groups.google.com/group/symfony-devs?hl=en

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to