JPA Hibernate Chamada Postgres Função Void Return MappingException:
Eu tenho um problema onde estou recebendo um:org.hibernate.MappingException: Nenhum mapeamento de dialeto para o tipo JDBC: 1111 ao tentar chamar uma função postgres usando JPA, crie uma consulta nativa.
Eu criei um timer EJB em um singleton de inicialização para executar uma função Postgres a cada 6 horas. A função retorna void e verifica os registros expirados, os exclui e atualiza alguns status. Não leva argumentos e retorna vazio.
A função postgres roda perfeitamente se eu a chamar usando a ferramenta de consulta PgAdmin (select function ();) e retorna void.
Quando eu implantar o aplicativo no Glassfish 3.1.1, recebo uma exceção e uma falha na implantação.
Este é o rastreamento de pilha (encurtado):
WARNING: A system exception occurred during an invocation on EJB UserQueryBean method public void com.mysoftwareco.entity.utility.UserQueryBean.runRequestCleanup()
javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean
...STACK TRACE BLAH BLAH BLAH ...
Caused by: javax.persistence.PersistenceException: org.hibernate.MappingException: No Dialect mapping for JDBC type: 1111
Aqui está o código:
Primeiro as coisas do JPA:
public void runRequestCleanup() {
String queryString = "SELECT a_function_that_hibernate_chokes_on()";
Query query = em.createNativeQuery(queryString);
Object result = query.getSingleResult();
}
Este é o singleton chamando-o:
@Startup
@Singleton
public class RequestCleanupTimer {
@Resource
TimerService timerService;
@EJB
UserQueryBean queryBean;
@PostConstruct
@Schedule(hour = "*/6")
void runCleanupTimer() {
queryBean.runRequestCleanup();
}
}
E a função:
CREATE OR REPLACE FUNCTION a_function_that_hibernate_chokes_on()
RETURNS void AS
$BODY$
DECLARE
var_field_id myTable.field_id%TYPE;
BEGIN
FOR var_field_id IN
select field_id from myTable
where status = 'some status'
and disposition = 'some disposition'
and valid_through < now()
LOOP
BEGIN
-- Do Stuff
END;
END LOOP;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;