{"action":"created","issue":{"url":"https://api.github.com/repos/querydsl/querydsl/issues/1934","repository_url":"https://api.github.com/repos/querydsl/querydsl","labels_url":"https://api.github.com/repos/querydsl/querydsl/issues/1934/labels{/name}","comments_url":"https://api.github.com/repos/querydsl/querydsl/issues/1934/comments","events_url":"https://api.github.com/repos/querydsl/querydsl/issues/1934/events","html_url":"https://github.com/querydsl/querydsl/issues/1934","id":161943345,"number":1934,"title":"Alias of CaseBuilder not working properly with JPAQuery","user":{"login":"renanleandrof","id":7140457,"avatar_url":"https://avatars.githubusercontent.com/u/7140457?v=3","gravatar_id":"","url":"https://api.github.com/users/renanleandrof","html_url":"https://github.com/renanleandrof","followers_url":"https://api.github.com/users/renanleandrof/followers","following_url":"https://api.github.com/users/renanleandrof/following{/other_user}","gists_url":"https://api.github.com/users/renanleandrof/gists{/gist_id}","starred_url":"https://api.github.com/users/renanleandrof/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/renanleandrof/subscriptions","organizations_url":"https://api.github.com/users/renanleandrof/orgs","repos_url":"https://api.github.com/users/renanleandrof/repos","events_url":"https://api.github.com/users/renanleandrof/events{/privacy}","received_events_url":"https://api.github.com/users/renanleandrof/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-06-23T14:54:23Z","updated_at":"2016-06-23T15:03:54Z","closed_at":null,"body":"```java\r\nStringExpression caseWhen = new CaseBuilder()                .when(expenses.code.in(SPECIAL_EXPENSES, EXTRA_EXPENSES))\r\n                .then(\"Special expenses\")\r\n                .otherwise(\"FInal expenses\")\r\n                .as(\"type\");\r\n\r\n        return getJPAQuery()\r\n                .select(new QDescricaoValor(\r\n                        caseWhen,\r\n                        expenses.value.sum()))\r\n                .from(expenses)\r\n                .where(expenses.year.eq(year))\r\n                .groupBy(Expressions.stringPath(\"type\"))\r\n                .orderBy(expenses.value.sum().desc())\r\n                .fetch();\r\n```\r\n\r\nThis code produces exception. It treats the alias as a column on the final SQL generated.\r\nIs it a bug on QueryDSL or a JPA limitation?\r\nThanks!"},"comment":{"url":"https://api.github.com/repos/querydsl/querydsl/issues/comments/228079232","html_url":"https://github.com/querydsl/querydsl/issues/1934#issuecomment-228079232","issue_url":"https://api.github.com/repos/querydsl/querydsl/issues/1934","id":228079232,"user":{"login":"renanleandrof","id":7140457,"avatar_url":"https://avatars.githubusercontent.com/u/7140457?v=3","gravatar_id":"","url":"https://api.github.com/users/renanleandrof","html_url":"https://github.com/renanleandrof","followers_url":"https://api.github.com/users/renanleandrof/followers","following_url":"https://api.github.com/users/renanleandrof/following{/other_user}","gists_url":"https://api.github.com/users/renanleandrof/gists{/gist_id}","starred_url":"https://api.github.com/users/renanleandrof/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/renanleandrof/subscriptions","organizations_url":"https://api.github.com/users/renanleandrof/orgs","repos_url":"https://api.github.com/users/renanleandrof/repos","events_url":"https://api.github.com/users/renanleandrof/events{/privacy}","received_events_url":"https://api.github.com/users/renanleandrof/received_events","type":"User","site_admin":false},"created_at":"2016-06-23T15:03:54Z","updated_at":"2016-06-23T15:03:54Z","body":"QueryDSL: 4.0.9\r\n\r\nI have changed the java code a little to keep it simple for you to read.\r\nMy code is a little bit different as produces JPQL like this:\r\n\r\n##Java code:\r\n```java\r\nStringExpression caseWhen = new CaseBuilder()\r\n                .when(despesas.id.funcionalProgramatica.funcao.codigo.in(CODIGO_ENCARGOS_ESPECIAIS, CODIGO_RESERVA_DE_CONTINGENCIA))\r\n                .then(ENCARGOS_ESPECIAIS_E_RESERVA_DE_CONTINGENCIA)\r\n                .otherwise(AREAS_DE_ATUACAO_FINALISTICAS)\r\n                .as(\"areasDeAtuacao\");\r\n\r\n        return getJPAQuery()\r\n                .select(new QDescricaoValor(\r\n                        caseWhen,\r\n                        despesas.valorPagamento.sum()))\r\n                .from(despesas)\r\n                .innerJoin(despesas.id.funcionalProgramatica)\r\n                .where(despesas.id.ano.eq(ano))\r\n                .groupBy(Expressions.stringPath(\"areasDeAtuacao\"))\r\n                .orderBy(despesas.valorPagamento.sum().desc())\r\n                .fetch();\r\n```\r\n\r\n##Exception:\r\n```\r\n12:02:25.379 [main] DEBUG org.hibernate.SQL - select case when funcionalp1_.CodFuncao in (? , ?) then ? else 'Áreas de atuação finalísticas' end as col_0_0_, sum(despesasan0_.ValPagamento) as col_1_0_ from dm_portal.despesas_FatDespesasAnoXFuncionalProgramatica despesasan0_ inner join dm_portal.corp_DimFuncionalProgramatica funcionalp1_ on despesasan0_.skFuncionalProgramatica=funcionalp1_.skFuncionalProgramatica where despesasan0_.NumAno=? group by areasDeAtuacao order by sum(despesasan0_.ValPagamento) desc\r\nHibernate: select case when funcionalp1_.CodFuncao in (? , ?) then ? else 'Áreas de atuação finalísticas' end as col_0_0_, sum(despesasan0_.ValPagamento) as col_1_0_ from dm_portal.despesas_FatDespesasAnoXFuncionalProgramatica despesasan0_ inner join dm_portal.corp_DimFuncionalProgramatica funcionalp1_ on despesasan0_.skFuncionalProgramatica=funcionalp1_.skFuncionalProgramatica where despesasan0_.NumAno=? group by areasDeAtuacao order by sum(despesasan0_.ValPagamento) desc\r\n12:02:25.386 [main] WARN  org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 42122, SQLState: 42S22\r\n12:02:25.386 [main] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Column \"AREASDEATUACAO\" not found; SQL statement:\r\nselect case when funcionalp1_.CodFuncao in (? , ?) then ? else 'Áreas de atuação finalísticas' end as col_0_0_, sum(despesasan0_.ValPagamento) as col_1_0_ from dm_portal.despesas_FatDespesasAnoXFuncionalProgramatica despesasan0_ inner join dm_portal.corp_DimFuncionalProgramatica funcionalp1_ on despesasan0_.skFuncionalProgramatica=funcionalp1_.skFuncionalProgramatica where despesasan0_.NumAno=? group by areasDeAtuacao order by sum(despesasan0_.ValPagamento) desc \r\n\r\n```\r\n\r\n"}}
{"actor":{"display_login":"renanleandrof"}}