java.sql.SQLException: Unknown column 'departmen4_1_.VALID_SECTOR' in 'where clause'

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • The following query works fine with a Classic query, however, doesn't work with ASTQueryTranslatorFactory. Note : Company has a collection of Departments. And, Department is a sub-class of Sectors. Company, Sectors, Department - all three are persited classes. The property validSector is on the parent class Sectors. For some reason, with ASTQueryTranslatorFactory, the select count clause's where with the parent class (SECTORS) property (validSector) doesn't generate the join on the table, but still has a where for that class correctly in the generated sql (departmen4_1_.VALID_SECTOR) --------------------------- error logs ------------- 2005-11-11 10:03:20,832 [http8080-Processor2] DEBUG HQLQueryPlan:132 - find: select distinct company from com.product..dao.transferobj.company as company left outer join company.departments as department where 1 = 1 AND ( company.cmpname LIKE :P0 ) AND ( size(company.departments) = 0 OR (select count(i) from company.departments i where i.validSector = :validSector) = 0 ) 2005-11-11 10:03:20,852 [http8080-Processor2] DEBUG QueryParameters:261 - named parameters: {P0=%, validSector=true} 2005-11-11 10:03:20,852 [http8080-Processor2] DEBUG Loader:1739 - bindNamedParameters() % -> P0 [1] 2005-11-11 10:03:20,852 [http8080-Processor2] DEBUG Loader:1739 - bindNamedParameters() true -> validSector [2] 2005-11-11 10:03:20,902 [http8080-Processor2] DEBUG JDBCExceptionReporter:63 - could not execute query [select distinct company0_.ID, company0_.CMP_NAME as OBJ1_61_ from COMPANY company0_ left outer join DEPARTMENT departmen1_ on company0_.ID=departmen1_.ID left outer join SECTORS sectors1_1_ on departmen1_.obid=sectors1_1_.ID where 1=1 and (company0_.CMP_NAME like ?) and ((select count(departmen3_.ID) from DEPARTMENT departmen3_ inner join SECTORS sectors3_1_ on departmen3_.ID=sectors3_1_.ID where company0_.ID=departmen3_.SPP_ID)=0 or (select count(departmen4_.obid) from DEPARTMENT departmen4_ where company0_.ID=departmen4_.SPP_ID and departmen4_1_.VALID_SECTOR=?)=0)] java.sql.SQLException: Unknown column 'departmen4_1_.VALID_SECTOR' in 'where clause' at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2847) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622) at com.mysql.jdbc.Connection.execSQL(Connection.java:2376) at com.mysql.jdbc.Connection.execSQL(Connection.java:2297) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1860) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1705) at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:137) at org.hibernate.loader.Loader.getResultSet(Loader.java:1676) at org.hibernate.loader.Loader.doQuery(Loader.java:662) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223) at org.hibernate.loader.Loader.doList(Loader.java:2147) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2026) at org.hibernate.loader.Loader.list(Loader.java:2021) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:298) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:137) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1014) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
    via by user1,
  • The following query works fine with a Classic query, however, doesn't work with ASTQueryTranslatorFactory. Note : Company has a collection of Departments. And, Department is a sub-class of Sectors. Company, Sectors, Department - all three are persited classes. The property validSector is on the parent class Sectors. For some reason, with ASTQueryTranslatorFactory, the select count clause's where with the parent class (SECTORS) property (validSector) doesn't generate the join on the table, but still has a where for that class correctly in the generated sql (departmen4_1_.VALID_SECTOR) --------------------------- error logs ------------- 2005-11-11 10:03:20,832 [http8080-Processor2] DEBUG HQLQueryPlan:132 - find: select distinct company from com.product..dao.transferobj.company as company left outer join company.departments as department where 1 = 1 AND ( company.cmpname LIKE :P0 ) AND ( size(company.departments) = 0 OR (select count(i) from company.departments i where i.validSector = :validSector) = 0 ) 2005-11-11 10:03:20,852 [http8080-Processor2] DEBUG QueryParameters:261 - named parameters: {P0=%, validSector=true} 2005-11-11 10:03:20,852 [http8080-Processor2] DEBUG Loader:1739 - bindNamedParameters() % -> P0 [1] 2005-11-11 10:03:20,852 [http8080-Processor2] DEBUG Loader:1739 - bindNamedParameters() true -> validSector [2] 2005-11-11 10:03:20,902 [http8080-Processor2] DEBUG JDBCExceptionReporter:63 - could not execute query [select distinct company0_.ID, company0_.CMP_NAME as OBJ1_61_ from COMPANY company0_ left outer join DEPARTMENT departmen1_ on company0_.ID=departmen1_.ID left outer join SECTORS sectors1_1_ on departmen1_.obid=sectors1_1_.ID where 1=1 and (company0_.CMP_NAME like ?) and ((select count(departmen3_.ID) from DEPARTMENT departmen3_ inner join SECTORS sectors3_1_ on departmen3_.ID=sectors3_1_.ID where company0_.ID=departmen3_.SPP_ID)=0 or (select count(departmen4_.obid) from DEPARTMENT departmen4_ where company0_.ID=departmen4_.SPP_ID and departmen4_1_.VALID_SECTOR=?)=0)] java.sql.SQLException: Unknown column 'departmen4_1_.VALID_SECTOR' in 'where clause' at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2847) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622) at com.mysql.jdbc.Connection.execSQL(Connection.java:2376) at com.mysql.jdbc.Connection.execSQL(Connection.java:2297) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1860) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1705) at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:137) at org.hibernate.loader.Loader.getResultSet(Loader.java:1676) at org.hibernate.loader.Loader.doQuery(Loader.java:662) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223) at org.hibernate.loader.Loader.doList(Loader.java:2147) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2026) at org.hibernate.loader.Loader.list(Loader.java:2021) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:298) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:137) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1014) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
    via by user1,
  • i am getting Hibernate error
    via Stack Overflow by Raji
    ,
    • java.sql.SQLException: Unknown column 'departmen4_1_.VALID_SECTOR' in 'where clause' at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2847) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622) at com.mysql.jdbc.Connection.execSQL(Connection.java:2376) at com.mysql.jdbc.Connection.execSQL(Connection.java:2297) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1860) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1705) at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:137) at org.hibernate.loader.Loader.getResultSet(Loader.java:1676) at org.hibernate.loader.Loader.doQuery(Loader.java:662) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223) at org.hibernate.loader.Loader.doList(Loader.java:2147) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2026) at org.hibernate.loader.Loader.list(Loader.java:2021) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:298) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:137) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1014) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)

    Users with the same issue

    Unknown visitor1 times, last one,
    ivanszkypeter
    ivanszkypeter452 times, last one,
    slash
    slash1 times, last one,
    musketyr
    musketyr1 times, last one,
    mauritius
    mauritius1 times, last one,
    20 more bugmates