我正在尝试将java.util.Date映射到不带时区类型的postgresql。我使用了一个自定义的sql-insert语句(因为表是分区的,postgresql不会返回在普通insert上更新的行数),并且我一直收到一个错误,指出该函数不存在。我怀疑这是由于映射这些日期字段的问题造成的。
从hibernate映射:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false">
<class ...snip...
<property name="dateCreated" type="timestamp">
<column name="DATE_CREATED"/>
</property>
<property name="dateUpdated" type="timestamp">
<column name="DATE_UPDATED"/>
</property>
...snip...
<sql-insert callable="true">{call insert_wal (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}</sql-insert>
</class>
</hibernate-mapping>在应用程序日志中:
Hibernate:
{call insert_wal (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}
12/06/09 17:22:15.409 WARN hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: null
12/06/09 17:22:15.425 ERROR hibernate.util.JDBCExceptionReporter - Batch entry 0 select * from insert_wal (foo, 439, ...snip... 2009-06-12 17:22:15.315000 -07:00:00, 2009-06-12 17:22:15.378000 -07:00:00, ...snip...) as result was aborted. Call getNextException to see the cause.
12/06/09 17:22:15.425 WARN hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 42883
12/06/09 17:22:15.425 ERROR hibernate.util.JDBCExceptionReporter - ERROR: function insert_wal(character varying, integer, ...snip... unknown, unknown, ...snip...) does not exist
12/06/09 17:22:15.425 ERROR event.def.AbstractFlushingEventListener - Could not synchronize database state with session(从第一个错误行中引用的getNextException返回的异常只是使用堆栈跟踪重复第二个错误行。)正如您所看到的,由于某些原因,JDBC正在寻找的函数签名具有“未知”作为时间戳所在位置的数据类型。我尝试了我能想到的所有属性类型和列sql类型的组合,但每次都显示为“未知”。下面是DB中函数定义的签名:
CREATE OR REPLACE FUNCTION insert_wal(p_action character varying, p_partner_id numeric, ...snip... p_date_created timestamp without time zone, p_date_updated timestamp without time zone, ...snip...唯一的其他区别是,在函数定义中有"numeric“的地方,错误行显示了各种类型,如”整数“、”双精度“和"bigint";并且函数定义中的一个参数是"text”类型,其中错误显示"character varying“。
我可以通过调用pgAdminIII中的函数来产生类似的错误,除了字符串值(例如带引号的'foo‘)是“未知的”,而日期值(我刚刚使用的now())被视为“带有时区的时间戳”。
那么:我是不是在hibernate映射中做错了什么?这是函数的问题吗?
发布于 2009-06-13 06:53:13
我对Hibernate的了解还不足以对这一部分进行评论,但您也许可以通过覆盖INSERT语句中的数据类型来解决这个错误:
<sql-insert callable="true">{call insert_wal (?::text, ?::numeric, <snip>?::timestamp, )::timestamp, <snip>)}</sql-insert>当然,您可能不需要覆盖所有字段,只需要覆盖那些引起问题的字段。
https://stackoverflow.com/questions/989732
复制相似问题