[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] criteriaquery : fetch not working
|
Hi Yannick,
You're right. If you fetch exactly the same thing as you were batching, you
will avoid the batch query because the LAZY relationship will be triggered by
the fetch and as a result there will be no need to trigger the batch.
Calling fetch twice in a row is not portable according to the spec. Although
It should work in EclipseLink (so feel free to use it). The hint is simply a
more portable way of doing it.
-Tom
Yannick Majoros wrote:
Hi Tom,
So, if I have @BatchFetch in the mapping *and* use root.fetch(A_.b),
@BatchFetch won't have any effect anyway, righ?
The thing I don't quite understand is about the hint. Can't I just do
root.fetch(A_.b).fetch(B_.c) to have multiple levels?
Regards,
Yannick
Le 2011-08-05 17:17, Tom Ware a écrit :
Hi Yannick,
There is not a way to disable the @BatchFetch when it is set on the
mapping.
root.fetch() will create a query that reads both sides of a
relationship. (i.e. the SELECT clause will retreive the fields
necessary to populate the other side of the relationship.
root.join() will join to the other side of the relationship without
actually reading the data on the other side of the relationship (i.e.
it only affects the FROM and WHERE clauses of generated queries)
batching will not cause the initial query to change. When you
traverse the batched relationship for one object retrieved by the
query, it will read the data for that same relationship for all the
other objects retreived by that query.
The link I passed you includes an additional way to add fetch joins
to a query. You can create a query and then add hints to the query
that will join. The nice thing about the hint is it goes beyond what
JPA allows by default because you can fetch to multiple levels. (e.g.
you can fetch a.b and a.b.c and a.b.c.d etc...)
-Tom
Yannick Majoros wrote:
Hi,
Thanks a lot, it's much better now :-) You put some light in the dark
zones in my mind concerning Eclipselink ;-)
I changed some defaults in the mapping (from default to lazy in most
cases).
I also added @BatchFetch annotations on some @OneToMany mappings.
Some things just never need to be read one by one. As I can't go into
the whole team's code (everyone doing things without too much
concertation), I think that's the best thing to do.
A few more questions:
- @BatchFetch introduces a nice default, but in some cases, such as
the one I was describing, I'd like to override that like this:
root.fetch(EtdOffEtd_.etdOffEtdSesCollection, JoinType.LEFT);
Now, if I do both this and leave the @BatchFecth annotation, it just
seems to do both. Is there a way to disable the batch fetch when needed?
- what's the difference between root.fetch() and root.join() in this
case?
- I don't really understand if the link you provided could help me
further? Could I still improve the code with this?
Best regards,
Yanncik
Le 4/08/2011 19:20, Tom Ware a écrit :
The default is LAZY for xToMany and EAGER for xToOne. To allow LAZY
to work on xToOne, you will have to not only ensure the mapping is
marked as LAZY, but also ensure EclipseLink can weave the classes.
The classes will be weaved by default on a Java EE 5 compliant
container. You will have to use set the eclispelink jar file as
with the -javaagent flag in Java SE if you are running standalone.
Other cases require other configuration - which are you using?
Looking more closely at your query, you are likely getting more
joins than you need. For instance, you are both fetch joining and
joining EtdOffEtd_.etdInscCoursCollection. Each of those will
result in a join.
You may want to consider using our fetch join query hint that allows
you to do multiple level fetch joins.
http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_%28ELUG%29#Join_Fetch
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users