javaenumsentityquarkus

Quarkus: Constructor in enum cannot be applied to given types


I am getting started with Quarkus and I'm trying to use an enum in my entity but I keep getting this error:

[ERROR] ~/ConnectorFormatEnum.java:[10,12] constructor ConnectorFormatEnum in enum *.ConnectorFormatEnum cannot be applied to given types;
[ERROR]   required: no arguments
[ERROR]   found:    java.lang.String,boolean
[ERROR]   reason: actual and formal argument lists differ in length

Here's my enum class:

@RequiredArgsConstructor
public enum ConnectorFormatEnum {
SOCKET("SOCKET",true),
CABLE("CABLE",true),
UNKNOWN(null,false);

private final String value;
private final Boolean ocpi;

@JsonValue
public String getValue() {
    return value;
  }
}

And here's my entity where I wanna use the enum:

@Data
@Entity
@Table(schema = "ocpi_locations", name = "connector")
public class ConnectorEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_connector")
private Long id;

@Column(name = "internal", nullable = false, insertable = true, updatable = false)
private String internal;

@Column(name = "id", length=36)
private String idConnector;


@Enumerated(EnumType.STRING)
@Type(type = "pgsql_enum")
@Column(name = "format")
private ConnectorFormatEnum format = ConnectorFormatEnum.UNKNOWN;

@Column(name = "voltage")
private Integer voltage;

@Column(name = "amperage")
private Integer amperage;

@Column(name = "terms_and_conditions")
private String termsAndConditions;

@CreationTimestamp
@Column(updatable = false)
private Instant createdAt;

@UpdateTimestamp
@Column(name="updated_at", nullable = false, insertable = false )
private Instant lastUpdated;

@UpdateTimestamp
@Column(name="deleted_at", nullable = false, insertable = false )
private Instant deletedAt;

}

I have other enums in my project as well that I am trying to use with other entities but I am getting the same error for all of them, am I doing something wrong here ?


Solution

  • Possible solution

    According to stacktrace, I believe you are only missing constructor in Enum :

    @RequiredArgsConstructor
    public enum ConnectorFormatEnum {
        SOCKET("SOCKET",true),
        CABLE("CABLE",true),
        UNKNOWN(null,false);
    
        private final String value;
        private final Boolean ocpi;
    
        // Add this constructor
        private ConnectorFormatEnum(String value, boolean ocpi) {
            this.value = value;
            this.ocpi = ocpi;
        }
    
        @JsonValue
        public String getValue() {
            return value;
        }
    }