JPA Hibernate Call Postgres Función Void Return MappingException:
Tengo un problema donde consigo un:org.hibernate.MappingException: No hay asignación de dialecto para el tipo JDBC: 1111 al intentar llamar a una función postgres utilizando JPA, crear una consulta nativa.
Creé un temporizador EJB en un singleton de inicio para ejecutar una función de Postgres cada 6 horas. La función devuelve void y comprueba los registros caducados, los elimina y actualiza algunos estados. No lleva argumentos y devuelve vacío.
La función postgres se ejecuta perfectamente si la llamo con la herramienta de consulta PgAdmin (seleccione function ();) y devuelve vacío.
Cuando implemento la aplicación en Glassfish 3.1.1 obtengo una excepción y una falla de implementación.
Esta es la traza de pila (acortada):
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
Aquí está el código:
Primero las cosas JPA:
public void runRequestCleanup() {
String queryString = "SELECT a_function_that_hibernate_chokes_on()";
Query query = em.createNativeQuery(queryString);
Object result = query.getSingleResult();
}
Este es el singleton llamándolo:
@Startup
@Singleton
public class RequestCleanupTimer {
@Resource
TimerService timerService;
@EJB
UserQueryBean queryBean;
@PostConstruct
@Schedule(hour = "*/6")
void runCleanupTimer() {
queryBean.runRequestCleanup();
}
}
Y la función:
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;