Consulta hibernate sem retornar todos os campos do banco

3 respostas
ViniMunhoz

Boa tarde,

Estou com um problema ao executar uma query, o que acontece é o seguinte, eu tenho uma classe “Projeto” mapeada com uma série de atributos e tenho uma query que deve retornar apenas alguns destes, mas quando eu mando ele popular o objeto ele lança um erro dizendo que ele não encontrou o valor.

O comando usado é: return this.session.createSQLQuery(sql).addEntity(Project.class).list();

Alguem sabe como eu faço para popular o objeto sem precisar pegar todos os valores na query?

Abraço
Vinícius

3 Respostas

R

Por favor inclua a listagem do erro para analisarmos.

ViniMunhoz

Bom dia!

Está é a listagem do erro…

09:55:54,855 DEBUG JDBCExceptionReporter:92 - could not execute query [SELECT pro.date_start FROM projects pro WHERE pro.active = 1 AND pro.type IN (1, 2, 3, 5, 6, 9, 10, 11) AND CURDATE() BETWEEN pro.date_start AND pro.date_end AND INSTR(pro.days_week, DAYOFWEEK(NOW())) > 0 AND (LENGTH(TRIM(pro.times)) = 0 OR (INSTR(pro.times, |)	> 0 AND CURTIME() BETWEEN CAST(SUBSTRING_INDEX(REPLACE(REPLACE(pro.times,  ', ‘’), ‘,’, ‘’), ‘|’,  1) AS TIME) AND CAST(SUBSTRING_INDEX(REPLACE(REPLACE(pro.times, ’ ', ‘’), ,, ‘’), |, -1) AS TIME))) ORDER BY pro.id_project]

java.sql.SQLException: Column id_project not found.

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)

at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1144)

at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2793)

at com.mchange.v2.c3p0.impl.NewProxyResultSet.getInt(NewProxyResultSet.java:2573)

at org.hibernate.type.IntegerType.get(IntegerType.java:51)

at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:184)

at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:173)

at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1121)

at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:588)

at org.hibernate.loader.Loader.doQuery(Loader.java:724)

at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)

at org.hibernate.loader.Loader.doList(Loader.java:2232)

at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)

at org.hibernate.loader.Loader.list(Loader.java:2124)

at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:312)

at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1723)

at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)

at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:175)

at br.com.mrpostman.dao.DAO.getActiveProjects(DAO.java:48)

at br.com.mrpostman.dao.teste.main(teste.java:18)

09:55:54,855  WARN JDBCExceptionReporter:100 - SQL Error: 0, SQLState: S0022

09:55:54,855 ERROR JDBCExceptionReporter:101 - Column id_project not found.

abraço
Vinícius

R

O problema parece estar na cláusula ORDER BY da consulta SQL:

Existe realmente um campo chamado ID_PROJECT na tabela PROJECTS?

Criado 22 de dezembro de 2009
Ultima resposta 23 de dez. de 2009
Respostas 3
Participantes 2