如何使用Hibernate处理Postgresql UUID

时间:2012-06-05 22:56:28

标签: java hibernate jpa uuid

我正在将JPA(Hibernate)添加到在Postgresql中使用uuids的项目中。 uuids是Postgresql uuid类型。

我跟着these instructions并添加了这样的Hibernate注释:

@Column(name = "uid")
@Type(type="pg-uuid")
private UUID uid;

Hibernate据称在Hibernate 3.6中添加了对Postgres UUID的支持。我已经尝试过Hibernate 3.6和4.0,但两者都抛出以下异常。

Exception显示Postgresql驱动程序正在尝试将uuid转换为long。我试过了9.0-801.jdbc4和9.1-901.jdbc4 Postgres驱动程序。我需要获得不同的数据库驱动程序吗?

Caused by: org.postgresql.util.PSQLException: Bad value for type long : dbada1e4-a165-4601-b34e-d08428cd81df
    at org.postgresql.jdbc2.AbstractJdbc2ResultSet.toLong(AbstractJdbc2ResultSet.java:2796)
    at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getLong(AbstractJdbc2ResultSet.java:2019)
    at org.postgresql.jdbc4.Jdbc4ResultSet.getBlob(Jdbc4ResultSet.java:52)
    at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getBlob(AbstractJdbc2ResultSet.java:335)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.hibernate.engine.jdbc.internal.proxy.AbstractResultSetProxyHandler.continueInvocation(AbstractResultSetProxyHandler.java:104)
    ... 32 more

0 个答案:

没有答案