1

I'm using SpringBoot and JPA.

Into my entity I have a status field mapped as enum. I would like to map e specific enum-value as NULL.

I tried something like this:

public enum Status {

        DELETED(null),
        ACTIVE(1);

        private final Integer type;

        Status(Integer type) {
            this.type = type;
        }

        public int getStatusValue() {
            return type;
        }

        public static Status from(int value) {
            return Status.values()[value];
        }
    }

But this approach do not works properly.

When I try to set DELETED value for my model and I try to save on the DB the status value is 0.

Is there a way to set DELETED status and to have NULL value on the database directly?

1 Answer 1

1

You need to use an attribute convertor for this use case - have a look at this question that shows the steps to follow - Spring Data JPA not using AttributeConverter in Spring Boot Application

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.