org.hibernate.QueryException: * only allowed inside aggregate functions in SELECT


Baia

When i try to call the service to get data from the remote database i get this error

Console log:

14:02:52,651 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/gasnaturalfenosa].[appServlet]] (http-localhost-127.0.0.1-8080-4) Servlet.service() para servlet appServlet lanzó excepción: java.lang.NullPointerException
    at com.gas.servicioImpl.ServicioEncuestaImpl.getEncuesta(ServicioEncuestaImpl.java:32) [classes:]
    at com.gas.rest.EncuestaController.getPueblos(EncuestaController.java:29) [classes:]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_79]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_79]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_79]
    at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_79]
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215) [spring-web-3.2.13.RELEASE.jar:3.2.13.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) [spring-web-3.2.13.RELEASE.jar:3.2.13.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) [spring-webmvc-3.2.13.RELEASE.jar:3.2.13.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:743) [spring-webmvc-3.2.13.RELEASE.jar:3.2.13.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:672) [spring-webmvc-3.2.13.RELEASE.jar:3.2.13.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:82) [spring-webmvc-3.2.13.RELEASE.jar:3.2.13.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:919) [spring-webmvc-3.2.13.RELEASE.jar:3.2.13.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:851) [spring-webmvc-3.2.13.RELEASE.jar:3.2.13.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953) [spring-webmvc-3.2.13.RELEASE.jar:3.2.13.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:844) [spring-webmvc-3.2.13.RELEASE.jar:3.2.13.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829) [spring-webmvc-3.2.13.RELEASE.jar:3.2.13.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:230) [spring-orm-3.2.13.RELEASE.jar:3.2.13.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:106) [spring-web-3.2.13.RELEASE.jar:3.2.13.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_79]

14:02:56,948 ERROR [stderr] (http-localhost-127.0.0.1-8080-4) org.hibernate.QueryException: * only allowed inside aggregate function in SELECT [SELECT *  FROM com.gas.modelo.Delegacion d ORDER BY d.delegacion ASC]

14:02:56,949 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.hibernate.hql.classic.SelectParser.token(SelectParser.java:146)

14:02:56,949 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.hibernate.hql.classic.ClauseParser.token(ClauseParser.java:109)

14:02:56,949 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.hibernate.hql.classic.ClauseParser.end(ClauseParser.java:136)

14:02:56,950 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.hibernate.hql.classic.PreprocessingParser.end(PreprocessingParser.java:145)

14:02:56,950 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.hibernate.hql.classic.ParserHelper.parse(ParserHelper.java:52)

14:02:56,950 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:240)

14:02:56,951 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:209)

14:02:56,951 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)

14:02:56,952 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)

14:02:56,952 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124)

14:02:56,952 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)

14:02:56,953 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)

14:02:56,953 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1770)

14:02:56,953 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at com.gas.daoImpl.DelegacionDaoImpl.getDelegaciones(DelegacionDaoImpl.java:29)

14:02:56,954 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at com.gas.servicioImpl.ServicioDelegacionImpl.getDelegaciones(ServicioDelegacionImpl.java:30)

14:02:56,954 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at com.gas.rest.DelegacionController.getDelegaciones(DelegacionController.java:30)

14:02:56,954 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

14:02:56,955 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

14:02:56,955 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

14:02:56,955 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at java.lang.reflect.Method.invoke(Method.java:606)

14:02:56,956 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)

14:02:56,956 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)

14:02:56,957 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)

14:02:56,957 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:743)

14:02:56,958 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:672)

14:02:56,958 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:82)

14:02:56,959 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:919)

14:02:56,959 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:851)

14:02:56,959 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)

14:02:56,960 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:844)

14:02:56,960 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)

14:02:56,961 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)

14:02:56,961 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

14:02:56,962 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)

14:02:56,962 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)

14:02:56,962 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:230)

14:02:56,963 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:106)

14:02:56,963 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)

14:02:56,964 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)

14:02:56,964 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)

14:02:56,965 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)

14:02:56,965 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)

14:02:56,966 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)

14:02:56,966 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

14:02:56,967 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

14:02:56,967 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)

14:02:56,967 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)

14:02:56,968 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)

14:02:56,968 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)

14:02:56,968 ERROR [stderr] (http-localhost-127.0.0.1-8080-4)   at java.lang.Thread.run(Thread.java:745)

This is how I query:

@Repository
public class DelegacionDaoImpl  implements DelegacionDao {

    @Autowired
    @Qualifier("sfGas")
    SessionFactory sf;

    Session session;    
    @SuppressWarnings("unchecked")
    public List<Delegacion> getDelegaciones(){
        try{
            Session session = sf.getCurrentSession();
            Query q = session.createQuery("SELECT *  FROM Delegacion d ORDER BY d.delegacion ASC");
            return (List<Delegacion>) q.list();
        }catch(Exception e){
            e.printStackTrace();
            return null;
        }
    }
}

The dao:

@Entity
@Table(name="catDelegacion")
public class Delegacion implements Serializable{

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="id_delegacion")
    private Integer id_delegacion;

    @Column(name="delegacion")
    private String delegacion;

    public Integer getId_delegacion() {
        return id_delegacion;
    }

    public void setId_delegacion(Integer id_delegacion) {
        this.id_delegacion = id_delegacion;
    }

    public static long getSerialversionuid() {
        return serialVersionUID;
    }




    public String getDelegacion() {
        return delegacion;
    }

    public void setDelegacion(String delegacion) {
        this.delegacion = delegacion;
    }
}

Why am I getting this error? What did i do wrong? In my spring project everything else works fine.

EDIT: Now I get this error

15:30:41,835 WARN  [org.hibernate.util.JDBCExceptionReporter] (http-localhost-127.0.0.1-8080-4) SQL Error: 0, SQLState: 42P01
15:30:41,836 ERROR [org.hibernate.util.JDBCExceptionReporter] (http-localhost-127.0.0.1-8080-4) ERROR: relation "catdelegacion" does not exist
  Position: 91
15:30:41,836 ERROR [stderr] (http-localhost-127.0.0.1-8080-4) org.hibernate.exception.SQLGrammarException: could not execute query

no catdelegacion, only catDelegacion

gerert3

This is Hibernate, and the query language is HQL, which is similar but not identical to SQL. If you want to Delegacionreturn the complete object, just say

FROM Delegacion d ORDER BY d.delegacion ASC

i.e. no select *. For more information on HQL, visit https://docs.jboss.org/hibernate/orm/3.3/reference/en/html/queryhql.html#queryhql-from

Related


Hibernate: org.hibernate.QueryException

Criano: I have an org.hibernate.QueryException and I'm having a hard time understanding why. The property langue_id which hibernate condition cannot resolve is defined in my entity Conditionnement. stack trace Caused by: org.hibernate.QueryException: could not

Hibernate: org.hibernate.QueryException

Criano: I have an org.hibernate.QueryException and I'm having a hard time understanding why. The property langue_id which hibernate condition cannot resolve is defined in my entity Conditionnement. stack trace Caused by: org.hibernate.QueryException: could not

Hibernate: org.hibernate.QueryException

Criano: I have an org.hibernate.QueryException and I'm having a hard time understanding why. The property langue_id which hibernate condition cannot resolve is defined in my entity Conditionnement. stack trace Caused by: org.hibernate.QueryException: could not

Hibernate: org.hibernate.QueryException

Criano: I have an org.hibernate.QueryException and I'm having a hard time understanding why. The property langue_id which hibernate condition cannot resolve is defined in my entity Conditionnement. stack trace Caused by: org.hibernate.QueryException: could not

org.hibernate.QueryException: not an association

Jones I want to add order by restricting a condition in Hibernate. I have two tables Event and MainEvent with a one-to-many relationship (MainEvent has many events). final Criteria criteria = getCurrentSession().createCriteria( Event.class);

org.hibernate.QueryException: Cannot resolve property

TO: I have the following JPA class. /** * The persistent class for the ACCOUNT database table. * */ @Entity @Table(name="ACCOUNT") public class Account implements Serializable { private static final long serialVersionUID = 1L; @Id @XmlID @Column(name="ACC

org.hibernate.QueryException: Cannot resolve property

TO: I have the following JPA class. /** * The persistent class for the ACCOUNT database table. * */ @Entity @Table(name="ACCOUNT") public class Account implements Serializable { private static final long serialVersionUID = 1L; @Id @XmlID @Column(name="ACC

org.hibernate.QueryException: Cannot resolve property

South Africa I have the following JPA class. /** * The persistent class for the ACCOUNT database table. * */ @Entity @Table(name="ACCOUNT") public class Account implements Serializable { private static final long serialVersionUID = 1L; @Id @XmlID @Column(

org.hibernate.QueryException: Cannot resolve property

TO: I have the following JPA class. /** * The persistent class for the ACCOUNT database table. * */ @Entity @Table(name="ACCOUNT") public class Account implements Serializable { private static final long serialVersionUID = 1L; @Id @XmlID @Column(name="ACC

org.hibernate.QueryException: Cannot resolve property

Chen Yuhua I want to get the sum of a column in a table. public class PaymentLogDAO extends AbstractModel<PaymentLog> { public PaymentLogDAO() { super(PaymentLog.class); } public BigDecimal sum(String keyword) { try {

org.hibernate.QueryException: Cannot resolve property: filename

Ankit Lamba: I am using Hibernate to get values Criteriafrom filenamea column of a table contaque_recording_log. but when i get the result it throws an exception org.hibernate.QueryException: Cannot resolve property: filename of com.contaque.hibernateTableMapp

org.hibernate.QueryException: Cannot resolve property: filename

Ankit Lamba: I am using Hibernate to get values Criteriafrom filenamea column of a table contaque_recording_log. but when i get the result it throws an exception org.hibernate.QueryException: Cannot resolve property: filename of com.contaque.hibernateTableMapp

org.hibernate.QueryException: Cannot resolve property: filename

Ankit Lamba: I am using Hibernate to get values Criteriafrom filenamea column of a table contaque_recording_log. but when i get the result it throws an exception org.hibernate.QueryException: Cannot resolve property: filename of com.contaque.hibernateTableMapp