Ola pessoal,
Eu andei vendo muitos tópicos a respeito e em nenhum eu consegui resolver meu problema. Eu tenho uma procedure que popula uma tabela temporaria e depois me passa um select da mesma. Com isso estou usando o hibernate e não estou conseguindo acertar o mapeamento. Gostaria da ajuda de voces. Estou usando o SQl Server.
Quando
minha aplicação executa esta proc o hibernate reclama:
DEBUG AreaDAO:239 could not execute query
org.hibernate.exception.SQLGrammarException: could not execute query
at
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
at
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2235)
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
com.techsupply.sagx.dao.hibernate.AreaDAO.findProblemasIdentificados(AreaDAO.java:237)
at
com.techsupply.sagx.model.business.AreaNegocioImpl.findProblemasIdentificados(AreaNegocioImpl.java:480)
at
com.techsupply.sagx.model.business.AreaNegocioImpl$$FastClassByCGLIB$$2b476087.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at
org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:685)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
at
com.techsupply.sagx.interceptor.AuditoriaLogRecordInterceptor.invoke(AuditoriaLogRecordInterceptor.java:65)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at
org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:623)
at
com.techsupply.sagx.model.business.AreaNegocioImpl$$EnhancerByCGLIB$$b0ce0ee6.findProblemasIdentificados(<generated>)
at
com.techsupply.sagx.view.servlet.JasperReportsServlet.doGet(JasperReportsServlet.java:256)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.SQLException: Invalid column name id_problemas.
Só que essa coluna esta declarada corretamente. Vejam:
hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.techsupply.sagx.model.entity.ProblemasIdentificados"
table="returnTempProblIdentified">
<id name="id" column="id_problemas">
<generator class="native">
<param name="sequence">seq_problemas</param>
</generator>
</id>
<property name="unidadeNegocio" column="unidade_negocio"/>
<property name="tipo" column="tipo"/>
<property name="total" column="total"/>
</class>
<sql-query name="problemasIdentificadosSQL" callable="true">
<return
class="com.techsupply.sagx.model.entity.ProblemasIdentificados">
<return-property name="id" column="id_problemas"/>
<return-property name="unidadeNegocio"
column="unidade_negocio"/>
<return-property name="tipo" column="tipo"/>
<return-property name="total" column="total"/>
</return>
{call get_problemas_identificados (:baseline,:notConform,:critico)}
</sql-query>
</hibernate-mapping>
Agora a procedure.
create procedure [dbo].[get_problemas_identificados]
@baseline int,
@notConform varchar(15),
@critico varchar(15)
as begin
set NoCount off
declare @idArea int
declare @nomeUnidade varchar(255)
declare @totalModerado int
declare @totalCritico int
declare @tempCount int
IF OBJECT_ID('tempdb..##returnTempProblIdentified') IS NOT NULL
TRUNCATE TABLE ##returnTempProblIdentified
ELSE
create table ##returnTempProblIdentified (id_problemas int
IDENTITY(1,1) , unidade_negocio varchar(255), tipo varchar(50), total int)
-- busca todas as áreas "topo"
declare crAreasTopo cursor local static for
select id_area, unidade_negocio
from area
where (unidade_negocio is not null)
and (fl_removido = 0)
open crAreasTopo
fetch crAreasTopo into @idArea, @nomeUnidade
while (@@fetch_status = 0) begin
-- calcula soma para esta área e respectivas sub-áreas
exec usp_count_trabalhos_por_area_e_tipo @idArea, 'Não Conforme',
@baseline, @tempCount out
set @totalModerado = @tempCount
exec usp_count_trabalhos_por_area_e_tipo @idArea, 'Crítico',
@baseline, @tempCount out
set @totalCritico = @tempCount
insert into ##returnTempProblIdentified(unidade_negocio, tipo, total)
values (@nomeUnidade, @notConform, @totalModerado)
insert into ##returnTempProblIdentified(unidade_negocio, tipo, total)
values (@nomeUnidade, @critico, @totalCritico)
fetch crAreasTopo into @idArea, @nomeUnidade
end
close crAreasTopo
deallocate crAreasTopo
select unidade_negocio,tipo,total from ##returnTempProblIdentified
end
A tabela mapeada é uma tabela temporaria para que ela pudesse ser retornada
pela consulta final.
Vejam o trecho do meu DAO.
Session session =
getHibernateTemplate().getSessionFactory().getCurrentSession();
List<ProblemasIdentificados> problemasIdenticados = new
ArrayList<ProblemasIdentificados>();
Map<String, String> map = new HashMap<String, String>();
Query query = null;
try {
if
(dialect.equalsIgnoreCase("org.hibernate.dialect.Oracle10gDialect")) {
query =
session.getNamedQuery("problemasIdentificadosOracle");
} else {
query = session.getNamedQuery("problemasIdentificadosSQL");
}
query.setInteger("baseline", baseLine);
query.setString("notConform", notConforme);
query.setString("critico", critico);
problemasIdenticados = query.list();
Alguem sabe o que pode estar de errado?
Obrigado