I am using Spring Boot.
I have the following table:
CREATE TYPE photo_status as enum('pending', 'completed', 'processing', 'failed');
CREATE TABLE photos (
uuid uuid DEFAULT gen_random_uuid() PRIMARY KEY,
url text NOT NULL,
status photo_status DEFAULT 'pending' NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL
);
When trying to save to the database, I get the following error:
ERROR: column "status" is of type photo_status but expression is of type character varying
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement
I think my problem is with the emum (PhotoStatus) in the Entity.
Question
I am unable to modify the SQL script to ALTER the table. So how can I change my Entity to work with the existing table?
Code
Entity
@Entity
@Table(name = "photos")
public class PhotoEntity {
public enum PhotoStatus {
pending,
complete,
processing,
failed
}
@Id
@Column(name = "uuid")
private UUID uuid;
@Column(name = "url", nullable = false)
private String url;
@Enumerated(EnumType.STRING)
@Column(columnDefinition = "photo_status", nullable = false)
private PhotoStatus status;
@Column(name = "created_at", nullable = false)
private LocalDateTime created_at;