Hibernate Exception - Unknown name value

I have the same problem as [ Hibernate Exception: Unknown name for class enum

But in my case

Unable to filter, so returning non filtered results.Unknown name value for enum class com.xxxx.enums.Status: DELIVERED
java.lang.IllegalArgumentException: Unknown name value for enum class com.xxxx.enums.Status: DELIVERED
    at org.hibernate.type.EnumType.nullSafeGet(EnumType.java:128)
    at org.hibernate.type.CustomType.nullSafeGet(CustomType.java:109)
    at org.hibernate.type.AbstractType.hydrate(AbstractType.java:104)


@Enumerated(value = EnumType.STRING)
@Column(name = "status", length = 10)
@AuditableField
private Status status;

public enum ReleaseStatus {
     DL("Delivered"),
}

Everything seems beautiful, but I get this exception.

+4
source share
2 answers

You have a row DELIVEREDin your table. And this line should be name()one of the instances ReleaseStatus. And ReleaseStatusdoes not have an instance named DELIVERED. The only one you posted is called DL.

, DL not DELIVERED. enum DELIVERED, , .

Hibernate , , "" , Hibernate enum, ( ). .

+9

, :

    @Column
    @Convert(converter = StatusFirmaDocumentoConverter.class)  <<<<< :)
    @AuditableField
    private Status status;

, :

public class CustomConverter implements AttributeConverter<Status, String> {

    @Override
    public String convertToDatabaseColumn(Status attribute) {
        return attribute.getValue() ;
    }

    @Override
    public Status convertToEntityAttribute(String dbData) {
        return  StatusFirmaDocumento.fromString(dbData);
    }

}

, , , " DL DELIVERED"

+7

Source: https://habr.com/ru/post/1545451/


All Articles