Setting default ENUM value

Hello, dear community.
Sorry for such a simple question, but does the CUBA platform provide an instrument to set a default value for ENUM fields? Or how can I do it as i init an entity editor?

Hi,

You can either set the default value for the entity field

@Column(name = "STATUS", nullable = false)
protected Integer status = OrderStatus.NEW.getId();

or within the Editor by overriding the initNewItem method:

@Override
protected void initNewItem(Order item) {
    item.setStatus(OrderStatus.NEW);
}

Regards,
Geleb

4 Likes

Additionally, a specific initialization method with a @PostConstruct annotation can be created in the entity class. In this case, any global infrastructure interfaces and beans can be invoked during initialization.

You can read more about Entity Fields Initialization in the documentation.

Regards,
Gleb

1 Like