我不能让Hibernate使用java.util.UUID for PostgreSQL.
这是使用javax.persistence的映射.*annotations:
private UUID itemUuid;
@Column(name="item_uuid",columnDefinition="uuid NOT NULL")
public UUID getItemUuid() {
return itemUuid;
}
public void setItemUuid(UUID itemUuid) {
this.itemUuid = itemUuid;
}
Run Code Online (Sandbox Code Playgroud)
当持久化对象时,我得到一个SQLGrammarException:
column "item_uuid" is of type uuid but expression is of type bytea at character 149
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud) 我的实体看起来像
@Entity
public class Member {
@Id
private UUID id;
@Column(name = "member_external_id", unique = true, nullable = false)
private String memberExternalId;
@Column(name = "client_id", unique = true, nullable = false)
private String clientId;
@Column(name = "client_secret", unique = true, nullable = false)
private String clientSecret;
@Column(unique = true, nullable = false)
private String email;
private boolean active;
@Column(name = "created_at")
private LocalDateTime createdAt;
public Member() {
// required by JPA
}
....
}
Run Code Online (Sandbox Code Playgroud)
当我使用PostgreSQL在OpenShift上部署我的应用程序时,我在日志中看到以下错误
Caused by: org.hibernate.exception.SQLGrammarException: could not …Run Code Online (Sandbox Code Playgroud) 我想将PostgreSQL的本机UUID类型与Java UUID一起使用.我使用Hibernate作为我的JPA提供程序和ORM.如果我尝试直接保存它,它只是在Postgres中保存为bytea.
我怎样才能做到这一点?
我正在使用 Hibernate 5.0 + Postgres 9.4
我的实体使用UUIDs 作为标识符。
该项目还使用hibernate-spatial.
该id属性被简单地注释为
@Id
@GeneratedValue
private UUID id;
Run Code Online (Sandbox Code Playgroud)
持久化任何实体(不仅是具有几何数据的实体)后,我收到以下错误:
column "id" is of type geometry but expression is of type uuid
Run Code Online (Sandbox Code Playgroud)
看起来映射到我的类型存在一些冲突;虽然我不是 Hibernate 类型映射的专家。
有没有人可以帮助我克服这个问题?