[ 
https://issues.apache.org/jira/browse/DELTASPIKE-1222?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16319075#comment-16319075
 ] 

Richard Juso commented on DELTASPIKE-1222:
------------------------------------------

[~johndament] Sorry, must have overlooked you commented on it.  Let me explain 
further.

What I wanted to accomplish is to leverage the  List<E> findBy(E example, 
SingularAttribute<E, ?>... attributes)  method  with a @Query annotation.   
Even though I am not using any extra parameters in the annotaton it doesn't 
work; looking at the source code it seems it just doesn't consider the @Query 
annotation.  Not sure if there is any other way to accomplish this without 
writing custom method.

Example: 
@Override
@Query(value = "select r from Range r where r.customId IN (select e.customId 
from EbsUserStub e)")
public abstract List<Range> findBy(Range range, SingularAttribute<Range, ?>... 
paramArrayOfSingularAttribute);

this will throw a Caused by: java.lang.IllegalArgumentException: Parameter with 
that position [1] did not exist.


I can of course do, bellow example, but then I loose the ability to pass the 
Range object as an example itself and I would need to create a method for each 
use case as oppose to just passing the example object.

@Query(value = "select r from Range r where r.customId IN (select e.customId 
from EbsUserStub e)")
public abstract List<Range> findCustomQry();





Would be very handy to pass additional paramenters along with the example 
object. Not sure if this would be possible, but if we use ie. findAdditonal 
queryMethod prefix, we could combine the functionality of findBy and passing 
additional parameters that could be used in the query annotation.

Example:

List<Range> findAdditional(E example, Map<String,Object> additionalQueryParams, 
SingularAttribute<E, ?>... paramArrayOfSingularAttribute);

@Query(value = "select r from Range r where r.customId IN (select e.customId 
from EbsUserStub e where e.someField = ?1)")



> Allow query by example method expression wtih @Query annotation
> ---------------------------------------------------------------
>
>                 Key: DELTASPIKE-1222
>                 URL: https://issues.apache.org/jira/browse/DELTASPIKE-1222
>             Project: DeltaSpike
>          Issue Type: New Feature
>          Components: Data-Module
>            Reporter: Richard Juso
>              Labels: features
>             Fix For: 1.8.2
>
>
> ability to either override findBy/findAll methods with @Query annotation 
> (without using params or using params, but also allowing the E example 
> pattern)  or add support for custom method expression that could be used for 
> this purpose.  the E example would only appy to the main Entity restrictions, 
> the additional params could apply to nested entities based on param index
> ie. @Query(value = "select r from Range r where r.customId IN (select 
> e.customId from EbsUserStub e)")
>       public abstract List<Range> findBy(Range paramE, 
> SingularAttribute<Range, ?> paramArrayOfSingularAttribute);
> or 
> @Query(value = "select r from Range r where r.customId IN (select e.customId 
> from EbsUserStub e)")
>       public abstract List<Range> findUsing(Range paramE, 
> SingularAttribute<Range, ?> paramArrayOfSingularAttribute);
> or 
> @Query(value = "select r from Range r where r.customId IN (select e.customId 
> from EbsUserStub e where e.miscField = ?2)")
>       public abstract List<Range> findByMiscField(Range paramE, 
> SingularAttribute<Range, ?> paramArrayOfSingularAttribute, String miscField);
> method expression could either be custom ie. findUsing,  findByEntityName, 
> findByMiscField or some other marker.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to