我有一个问题,我得到一个: org.hibernate.MappingException: No Dialect mapping for JDBC type: 1111 当尝试使用 JPA 创建 native 查询调用 postgres 函数时。
我在启动单例中创建了一个 EJB 计时器,每 6 小时运行一次 Postgres 函数。该函数返回 void 并检查过期记录、删除它们并更新一些状态。它不接受任何参数并返回 void。
这是(缩短的)堆栈跟踪:
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
这是代码:
首先是JPA的东西:
public void runRequestCleanup() {
String queryString = "SELECT a_function_that_hibernate_chokes_on()";
Query query = em.createNativeQuery(queryString);
Object result = query.getSingleResult();
}
这是调用它的单例:
@Startup
@Singleton
public class RequestCleanupTimer {
@Resource
TimerService timerService;
@EJB
UserQueryBean queryBean;
@PostConstruct
@Schedule(hour = "*/6")
void runCleanupTimer() {
queryBean.runRequestCleanup();
}
}
和功能:
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;
最佳答案
这可能是一个黑客,但它对我有用,而且非常简单。只需将查询更改为:
SELECT count(*) FROM your_function();
现在它返回一个正确的整数,hibernate 很高兴。
关于hibernate - JPA Hibernate 调用 Postgres 函数无效返回映射异常 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12557957/