2014-11-05 106 views
7

我的实体看起来像错误:列“ID”的类型UUID的,但表达BYTEA类型

@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 
    } 
    .... 
} 

当我部署我的OpenShift PostgreSQL的应用程序中,我看到下面的日志中的错误

Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement 
    at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:123) [hibernate-core-4.3.5.Final.jar:4.3.5.Final] 
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) [hibernate-core-4.3.5.Final.jar:4.3.5.Final] 
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126) [hibernate-core-4.3.5.Final.jar:4.3.5.Final] 
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112) [hibernate-core-4.3.5.Final.jar:4.3.5.Final] 
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:190) [hibernate-core-4.3.5.Final.jar:4.3.5.Final] 
    at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:62) [hibernate-core-4.3.5.Final.jar:4.3.5.Final] 
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3124) [hibernate-core-4.3.5.Final.jar:4.3.5.Final] 
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3581) [hibernate-core-4.3.5.Final.jar:4.3.5.Final] 
    at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:104) [hibernate-core-4.3.5.Final.jar:4.3.5.Final] 
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:463) [hibernate-core-4.3.5.Final.jar:4.3.5.Final] 
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:349) [hibernate-core-4.3.5.Final.jar:4.3.5.Final] 
    at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350) [hibernate-core-4.3.5.Final.jar:4.3.5.Final] 
    at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56) [hibernate-core-4.3.5.Final.jar:4.3.5.Final] 
    at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1222) [hibernate-core-4.3.5.Final.jar:4.3.5.Final] 
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:1335) [hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final] 
    ... 203 more 
Caused by: org.postgresql.util.PSQLException: ERROR: column "id" is of type uuid but expression is of type bytea 
    Hint: You will need to rewrite or cast the expression. 
    Position: 130 
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2062) [postgresql-9.2-1003-jdbc4.jar:] 
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1795) [postgresql-9.2-1003-jdbc4.jar:] 
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257) [postgresql-9.2-1003-jdbc4.jar:] 
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:479) [postgresql-9.2-1003-jdbc4.jar:] 
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:367) [postgresql-9.2-1003-jdbc4.jar:] 
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:321) [postgresql-9.2-1003-jdbc4.jar:] 
    at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:493) 
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:187) [hibernate-core-4.3.5.Final.jar:4.3.5.Final] 
    ... 213 more 

OpenShift具有PostgreSQL的9.2版本。

enter image description here

,我使用连接到数据库的依赖性看起来像

<dependency> 
    <groupId>org.postgresql</groupId> 
    <artifactId>postgresql</artifactId> 
    <version>9.2-1003-jdbc4</version> 
</dependency> 

有没有人见过这个问题?我不知道如何解决它。

+0

http://stackoverflow.com/questions/11284359/persisting-uuid-in-postgresql-using-jpa 看看这个链接.. – 2014-11-05 07:32:36

+0

尝试了所有,他们没有工作! – daydreamer 2014-11-05 15:00:53

+0

在这个问题上的任何更新?你能分享你如何解决它吗? – klappvisor 2015-08-12 15:25:25

回答

6

尝试增加类型注释到 的UUID类型例如

@Type(type = "pg-uuid") 
@Column(name = "id", columnDefinition = "uuid") 
private UUID id; 

我只是工作过去同样的错误

相关问题