【发布时间】:2010-11-02 15:34:01
【问题描述】:
我正在尝试将 java.util.Date 映射到没有时区类型的 postgresql 时间戳。我正在使用自定义 sql-insert 语句(因为表已分区,并且 postgresql 不会返回在正常插入时更新的行数),并且我不断收到错误消息,指出该函数不存在。我怀疑这是由于映射这些日期字段的问题。
来自休眠映射:
<?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
(从第一个 ERROR 行中引用的 getNextException 返回的异常只是重复了带有堆栈跟踪的第二个 ERROR 行。)如您所见,由于某种原因,JDBC 正在寻找的函数签名具有“未知”作为数据类型时间戳在哪里。我已经尝试了所有我能想到的属性类型和列 sql-type 的组合,但每次都显示为“未知”。这是数据库中函数定义的签名:
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...
唯一的其他区别是函数定义中有“数字”的地方,错误行显示各种类型,如“整数”、“双精度”和“大整数”;并且函数定义中的一个参数是类型“text”,其中错误显示“字符变化”。
我可以通过调用 pgAdminIII 中的函数来产生类似的错误,除了它是“未知”的字符串值(例如,带引号的 'foo'),而日期值(我刚刚使用 now())被处理作为“带时区的时间戳”。
那么:我在休眠映射中做错了吗?是不是功能有问题?
【问题讨论】:
标签: hibernate postgresql jdbc types