'Element Collection not retrieving from Database

I am working with the Spring Boot Jpa Data Structure. I have after successful test runs without a database been able to run my code flawlessly. After having hooked up my Spring Boot Application to a MySQL database and saving values into it, I run into the following issue:

Upon retrieving the data from database after restarting my application the List with the @ElementCollection is empty. I have checked the database and the data is present within the database, all other data is also retrieved without error. The application produces no error other than a Null Pointer which can be traced back to the value of the list being null. Here is the code which is failing:

@Entity
public class Entity extends SuperEntity {

    @ElementCollection
    @LazyCollection(LazyCollectionOption.FALSE)
    private List<String> flags;

    public Entity() {
        super();
        this.flags = new LinkedList<>();
    }

    public Entity(List<String> flags) {
        super();
        this.flags = flags;
    }

    public Entity(@NotNull FormEntity formEntity) {
        super();
        this.flags = formEntity.getFlags();
    }

    public List<String> getFlags() {
        return flags;
    }
 
    public void setFlags(List<String> flags) {
        this.flags = flags;
    }
}

@Entity
public abstract class SuperEntity {

    protected @Id UUID id  = UUID.randomUUID();

    public SuperEntity() {}

    public UUID getId() {
        return id;
    }

    public void setId(UUID id) {
        this.id = id;
    }
}

Any help is greatly appreciated and any additional materials needed from my end will be provided.



Solution 1:[1]

Set the fetch type to Eager, worked for me

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yessir