Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order By Using Functions #51

Open
islemus opened this issue Sep 12, 2016 · 0 comments
Open

Order By Using Functions #51

islemus opened this issue Sep 12, 2016 · 0 comments

Comments

@islemus
Copy link

islemus commented Sep 12, 2016

Hi Xavier,

First of all, thanks torpedoquery is really awesome! However I am having a hard time sorting on multiple potentially empty columns

SELECT
    COALESCE([individual].[last_name], [individual].[first_name], [enterprise].[registered_name], [enterprise].[trade_name]) AS [customer_name]
        from customer
        LEFT JOIN individual individual on individual.id = customer.id
        LEFT JOIN enterprise enterprise ON enterprise.id = customer.id

order by COALESCE(individual.last_name, individual.first_name, enterprise.registered_name, enterprise.trade_name)
/* OR Simply */
order by customer_name

In torpedo I am able to declare and use the following function in the select statement, but using it in the orderyBy causes a null pointer exception

final Customer customer = from(Customer.class);
final Individual individual = extend(customer, Individual.class);
final Enterprise enterprise = extend(customer, Enterprise.class);
final Function<String> sortingName = coalesce(enterprise.getTradeName(), enterprise.getRegisteredName(), individual.getLastName(), individual.getFirstName());

//This works
select(sortingName);

//This throws a NullPointerException
orderBy = asc(sortingName);
Caused by: java.lang.NullPointerException
        at org.torpedoquery.jpa.Torpedo$3.handle(Torpedo.java:702)
        at org.torpedoquery.jpa.Torpedo$3.handle(Torpedo.java:698)
        at org.torpedoquery.jpa.internal.handlers.AbstractCallHandler.handleValue(AbstractCallHandler.java:63)
        at org.torpedoquery.jpa.internal.handlers.ArrayCallHandler.handleCall(ArrayCallHandler.java:46)
        at org.torpedoquery.jpa.internal.handlers.ArrayCallHandler.handleCall(ArrayCallHandler.java:26)
        at org.torpedoquery.jpa.internal.utils.TorpedoMethodHandler.handle(TorpedoMethodHandler.java:107)
        at org.torpedoquery.jpa.Torpedo.orderBy(Torpedo.java:697)
        at com.sti.uciscore.transaction.report.bean.ReportLoadServicesBean.createBillingConsumptionExceptionReportQuery(ReportLoadServicesBean.java:131)
        at com.sti.uciscore.transaction.report.bean.ReportLoadServicesBean.generateReport(ReportLoadServicesBean.java:74)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:437)
        at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:82)
        at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:93)
        at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:437)
        at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:64)
        at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:83)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
        at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:52)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51)
        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
        at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:275)
        ... 76 more

Is there a way to achieve this? (for instance reproducing the SQL select (expression) as alias order by alias)

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant