ERROR: column "id" is of type uuid but expression is of type bytea
Asked Answered
B

3

13

My entity looks like

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

When I deploy my application on OpenShift with PostgreSQL, I see following error in logs

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 has PostgreSQL version 9.2.

enter image description here

The dependency that I am using to connect to database looks like

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

Has anyone seen this issue? I don't know how to resolve it.

Burchfield answered 5/11, 2014 at 3:18 Comment(3)
#11284859 check out this link..Carminecarmita
tried all, none of them worked!Burchfield
any update on this issue? could you please share how you solved it?Antiquary
F
13

Try adding a type annotation onto the UUID type e.g.

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

I just worked past the same error

Furriery answered 30/9, 2015 at 14:57 Comment(0)
T
1

This is how I resolved it:

  1. I added a dependency on eclipselink JPA https://mvnrepository.com/artifact/org.eclipse.persistence/org.eclipse.persistence.jpa

  2. I added a converter to my UUID

    @Id
    @TypeConverter(name = "uuidConverter", dataType = Object.class, objectType = UUID.class)
    private UUID uuid;
Twelvemonth answered 13/2, 2018 at 10:12 Comment(0)
P
0
@Id
@GeneratedValue(strategy = GenerationType.UUID)
private UUID id;

Added strategy.

Pavid answered 25/1, 2023 at 5:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.