mysql - Spring Data JPA: @Query gives error java.sql.SQLException: Column 'id' not found -
i trying run following query
@org.springframework.stereotype.repository public interface reportingparamrepository extends repository<reportingparamdao, integer> { @query(nativequery = true, value = "select student, avg(height) reportingparams group student") public list<reportingparamdao> getaveragegroupbystudent(); }
this dao
@entity @table(name = "reportingparams") @namedquery(name = "reportingparams.findall", query = "select r reportingparamdao r") public class reportingparamdao extends basedao<integer, reportingparam> implements dao<integer> { private static final long serialversionuid = 1l; @id @generatedvalue(strategy = generationtype.identity) @column(unique = true, nullable = false) private integer id; @manytoone @joincolumn(name = "student", nullable = true) private studentdao studentbean; @column private long height; public integer getid() { return id; } public void setid(integer id) { this.id = id; } public studentdao getstudentbean() { return studentbean; } public void setstudentbean(studentdao studentbean) { this.studentbean = studentbean; } public long getheight() { return height; } public void setheight(long height) { this.height = height; } }
but on executing repository method following error
java.sql.sqlexception: column 'id' not found. @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:964) ~[mysql-connector-java-5.1.43.jar:5.1.43] @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:897) ~[mysql-connector-java-5.1.43.jar:5.1.43] @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:886) ~[mysql-connector-java-5.1.43.jar:5.1.43] @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:860) ~[mysql-connector-java-5.1.43.jar:5.1.43] @ com.mysql.jdbc.resultsetimpl.findcolumn(resultsetimpl.java:1077) ~[mysql-connector-java-5.1.43.jar:5.1.43] @ com.mysql.jdbc.resultsetimpl.getint(resultsetimpl.java:2567) ~[mysql-connector-java-5.1.43.jar:5.1.43] @ org.apache.commons.dbcp2.delegatingresultset.getint(delegatingresultset.java:283) ~[commons-dbcp2-2.1.1.jar:2.1.1] @ org.apache.commons.dbcp2.delegatingresultset.getint(delegatingresultset.java:283) ~[commons-dbcp2-2.1.1.jar:2.1.1] @ org.hibernate.type.descriptor.sql.integertypedescriptor$2.doextract(integertypedescriptor.java:62) ~[hibernate-core-5.0.12.final.jar:5.0.12.final] @ org.hibernate.type.descriptor.sql.basicextractor.extract(basicextractor.java:47) ~[hibernate-core-5.0.12.final.jar:5.0.12.final] @ org.hibernate.type.abstractstandardbasictype.nullsafeget(abstractstandardbasictype.java:238) ~[hibernate-core-5.0.12.final.jar:5.0.12.final] @ org.hibernate.type.abstractstandardbasictype.nullsafeget(abstractstandardbasictype.java:234) ~[hibernate-core-5.0.12.final.jar:5.0.12.final] @ org.hibernate.type.abstractstandardbasictype.nullsafeget(abstractstandardbasictype.java:224) ~[hibernate-core-5.0.12.final.jar:5.0.12.final] @ org.hibernate.type.abstractstandardbasictype.hydrate(abstractstandardbasictype.java:300) ~[hibernate-core-5.0.12.final.jar:5.0.12.final] @ org.hibernate.loader.loader.extractkeysfromresultset(loader.java:789) ~[hibernate-core-5.0.12.final.jar:5.0.12.final] @ org.hibernate.loader.loader.getrowfromresultset(loader.java:714) ~[hibernate-core-5.0.12.final.jar:5.0.12.final] @ org.hibernate.loader.loader.processresultset(loader.java:972) ~[hibernate-core-5.0.12.final.jar:5.0.12.final] @ org.hibernate.loader.loader.doquery(loader.java:930) ~[hibernate-core-5.0.12.final.jar:5.0.12.final] @ org.hibernate.loader.loader.doqueryandinitializenonlazycollections(loader.java:336) ~[hibernate-core-5.0.12.final.jar:5.0.12.final] @ org.hibernate.loader.loader.dolist(loader.java:2617) ~[hibernate-core-5.0.12.final.jar:5.0.12.final] @ org.hibernate.loader.loader.dolist(loader.java:2600) ~[hibernate-core-5.0.12.final.jar:5.0.12.final] @ org.hibernate.loader.loader.listignorequerycache(loader.java:2429) ~[hibernate-core-5.0.12.final.jar:5.0.12.final] @ org.hibernate.loader.loader.list(loader.java:2424) ~[hibernate-core-5.0.12.final.jar:5.0.12.final] ...
if run query directly mysql terminal works fine , proper output. can please help? !!
this can't work. query fetches student object, trying map list of reportingparamdao's.
Comments
Post a Comment