Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Conditional LEFT JOIN in JPQL

Hi Tom,

I have a few questions regarding

1) Can I use a DTO constructor in the EL API query such as in the
attached tescase: select new dto.ProductWithFavoriteDTO(p, f) from
Product left join p.favorites f

2) Can I pass a parameter userId into such a query. If not, is addressing this?

I need this behavior because the query is expensive. Please refer to

3) How can I manipulate this query in such a way that it is cached in
EntityManager across sessions, much like a @NamedQuery with

Tom, thanks again for your help. I don't want to sound too demanding,
but as a suggestion my questions could be addressed in an easy way by
extending the testcase attached to

This might be useful for other people too, and it could be posted as
an example (being as simple as it is), and in case of future questions
one could just link to it.

Many thanks,


On Tue, 11 May 2010 08:20:05 -0400, you wrote:

>Hi Bernard, Vidas,
>   The best way to get this feature to the top of our implementation list is to 
>vote for it.  One of the main criteria we use when determining which features to 
>implement next is the number of distinct votes.
>   I have updated the bug with some information about how to define a query that 
>retrieves multiple items.
>   If you want to dynamically define a QueryKey, I believe it should work at the 
>moment.  You will have to use a small amount in internal API.  Here is some 
>pseudo code for the basic steps.
>   ServerSession session = 
>   ClassDescriptor descriptor = session.getDescriptor(MyEntity.class);
>   descriptor.addQueryKey(myQueryKey);
>   myQueryKey.initialize(descriptor);
>   The changes that allow JPQL queries to use query keys will be in our 2.1 
>release.  They appear in our nightly builds starting with last night's build.
>Vidas Timukas wrote:
>> Hi, Bernard,
>>   Know nothing about EL API, but, according to Tom's example, might it 
>> be possible to define queryKey on the fly with User.getId() as 
>> ConstantExpression and destroy it after query execution. Maybe Tom can 
>> suggest something about this.
>>   Another question, which rises, how to retrieve both objects in result 
>> list, like List<Product, Favourite>, because ReadAllQuery(Product.class) 
>> from given example seems to return only list of Products.
>>   And last question for Tom: As you said, there is some work to support 
>> queryKeys in JPQL. Can you tell us, in which version of EL it will be 
>> supported:? For example:
>>   SELECT p, f FROM Product p join p.favouritepk f 
>> 2010/5/11 <bht@xxxxxxxxxxxxx <mailto:bht@xxxxxxxxxxxxx>>
>>     Hello Vidas,
>>     I created a testcase and Tom responded to it:
>>     Can you believe that even with the current EclipseLink version, using
>>     the proprietary EclipseLink API, it is not possible to write a query
>>     with a conditional join where the condition comes from a parameter
>>     value?
>>     This is the simplest case I have been able to suggest. So no userId
>>     parameter for the query :(.
>>     It looks like I have to wait for some time (months?, a year?) before
>>     this is implemented, even before the spec is changed.
>>     Would you have any comment? Please vote for this.
>>     Best regards,
>>     Bernard
>>     _______________________________________________
>>     eclipselink-users mailing list
>>     eclipselink-users@xxxxxxxxxxx <mailto:eclipselink-users@xxxxxxxxxxx>
>> -- 
>> Sincerely,
>> Vidas
>> ------------------------------------------------------------------------
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@xxxxxxxxxxx
>eclipselink-users mailing list

Back to the top