0

I'm currently building a REST API using Kotlin/SpringBoot. As a database, I opted for PostgreSQL. When I run the application, I can create a new User (using Postman). However, when I try to perform the same action in my tests, I receive the following error:

org.postgresql.util.PSQLException: ERROR: column "uuid" is of type bytea but expression is of type uuid

The thing is I don't know how/where my column is interpreted as bytea. I did set up uuid as the datatype in my sql migration.

Here's my sql:

CREATE TABLE IF NOT EXISTS users (
    id BIGINT auto_increment,
    uuid UUID NOT NULL,
    name TEXT,
    password TEXT,
    created_at TIMESTAMP,
    updated_at TIMESTAMP,
    PRIMARY KEY (id)
);

Here's the Entity:

@Entity
@Table(name = "users")
data class UserEntity(

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    val id: Long,

    @Column(name = "uuid", unique = true, updatable = false, columnDefinition = "uuid")
    val uuid: UUID,

    val name: String,

    val password: String,

    @Column(name="created_at")
    val createdAt: LocalDateTime,

    @Column(name="updated_at")
    val updatedAt: LocalDateTime
)

And here's the application.properties at my test level:

spring.jpa.database=POSTGRESQL
spring.datasource.platform=postgres
spring.datasource.url=jdbc:postgresql://localhost:5432/forum?useSSL=false
spring.jpa.show-sql=true

spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect

I tried to switch my postgres build from runtimeOnly to implementation (I'm using gradle) Even try to specified the dialect, but nothing changed

  • `PostgreSQLDialect` is deprecated, you should use the dialect corresponding to your Postgres version. Not sure if that will fix your issue tho. In one of my projects, I had to add `@Access(AccessType.PROPERTY)` to UUID fields to avoid issues with Hibernate. You can also try the library `hibernate-types` to extends the types. – Guillaume F. May 19 '23 at 04:50
  • Maybe [this](https://stackoverflow.com/questions/4495233/postgresql-uuid-supported-by-hibernate) will help. – SternK May 20 '23 at 10:00
  • I'va updated the Dialect and try various thing, including `@Access` and `@Type`. But as far as I can tell, my problem is the other way around. Hibernate manage to create a statement as a UUID but the column in my DB is set as bytea and not as UUID. All the info I've found so far was about people having a column set to UUID but the statement as bytea (which is the opposite of my error). And I still can't figure out why or where the problem lies. – Mattias BASLE May 24 '23 at 17:54

0 Answers0