我无法让Hibernate与PostgreSQL一起使用java.util.UUID。
这是使用javax.persistence.*注释的映射:
private UUID itemUuid;
@Column(name="item_uuid",columnDefinition="uuid NOT NULL")
public UUID getItemUuid() {
return itemUuid;
}
public void setItemUuid(UUID itemUuid) {
this.itemUuid = itemUuid;
}
当持久化一个瞬态对象时,我会得到一个 SQLGrammarException 异常:column "item_uuid" is of type uuid but expression is of type bytea at character 149
PostgreSQL版本为8.4.4
JDBC驱动程序- 8.4.4-702(也尝试了9.0-相同的情况)
Hibernate版本为3.6,主要配置属性:
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://192.168.1.1/db_test</property>
registerHibernateType(Types.OTHER,"pg-uuid");
- Steve EbersoleH2
数据库。Caused by: org.hibernate.MappingException: No Dialect mapping for JDBC type: 1111
。 - daydreamer@Type(type="pg-uuid")
未被识别。我使用@Type(type="org.hibernate.type.PostgresUUIDType")
来解决这个问题。 - Sri