Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] ReadAllQuery fetch all

Hello Martin,

I do not believe joining (or batch reading, another option) on a collection mapping will work when using a cursor. Joining will cause multiple rows to be associated to the object, but the cursor will prevent going through the entire result set to build the object, so the returned objects will be based on a single row - and so collections will be incomplete. Batching may work, but since the batch query to bring in references is based on the original query, it negates the value of using a cursor as all the collection objects will be read in at once. What I would suggest instead is using pagination to read in batches - for instance ordering results and setting the first row/max results on the query object to return a manageable size of results. A fetch join can then be used since all rows returned will be used to create the objects.

Best Regards,
Chris

Janda Martin wrote:
Thank you, I tried "addJoinedAttribute" but theres problem. It doesn't work. It changed generated SQL command to use "select distinct e ..." instead of "select o ...".

<entityClass> has 4 lazy,optional OneToMany mappings that I nead to be fetched.

    @OneToMany(mappedBy = "datas", cascade = CascadeType.ALL)
    @OrderBy("dataType, azimut")
    private List<DData> dDataCollection;


ReadAllQuery readAllQuery = new ReadAllQuery(<entityClass>);
readAllQuery.setJPQLString("select object(o) from <table>");

ScrollableCursorPolicy policy = new ScrollableCursorPolicy();
policy.setPageSize(200);
policy.setResultSetType(ScrollableCursorPolicy.TYPE_SCROLL_INSENSITIVE);
policy.setResultSetConcurrency(ScrollableCursorPolicy.CONCUR_READ_ONLY);

readAllQuery.useScrollableCursor(policy);

// your suggestion
readAllQuery.addJoinedAttribute(readAllQuery.getExpressionBuilder().anyOf("dDataCollection"));
// or - second one uses "get" instead of "anyOf" - throws exception
readAllQuery.addJoinedAttribute("dDataCollection");
// select distinct ... is generated on query execution

ScrollableCursor scrollableCursor = (ScrollableCursor) uow.executeQuery(readAllQuery);


I've tried FetchGroup but I get exception that FetchGroupManager isn't set/installed.

Correctly and as I expect works only fetch = EAGER. There is generated new select DData for every entity.

It would be great to have some kind of QueryHint/boolean property on DatabaseQuery to disable lazy loading.

  Please can you give me another advice how to make it. I think that my problem is typical for Java SE applications when you need select some entities from database. Close all connections and run some computation on selected entities.

  Martin

----- Original Message -----
From: "Tom Ware" <tom.ware@xxxxxxxxxx>
To: "EclipseLink User Discussions" <eclipselink-users@xxxxxxxxxxx>
Sent: Tuesday, November 17, 2009 3:09:44 PM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna
Subject: Re: [eclipselink-users] ReadAllQuery fetch all

Hi Martin,

If you are using JPQL, JPQL allows you to specify fetch joins that will cause relationships to be automatically loaded. Have you tried that?

If you are using EclipseLink expressions, there is an addJoinedAttribute method you can use on your query.

-Tom

Martin Janda wrote:
Hello,
can you help me? please. I have Entity with lazy mappings. I need to read all Entity attributes Eager&Lazy trough ReadAllQuery (ScrollableCursor) and detach them. I need to use Entities after closing EM and EMF. So they can no longer fetch lazy mappings. I need to work with selected Entities from JTable (needs lazy) in another context (needs all attributes including lazy mappings). Is there any way how to do it in EclipseLink 1.1.3 Java SE, I prefer annotations or direct methods in EM/EMF/UOW.
Thank you very much.
   Martin

PS Sorry for my english
_______________________________________________
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


Back to the top