You must specify the initial state for new instances of your entity:
Figure 1. Specifying the initial state/**
* Defaults the state to
* {@linkplain MYLIFECYCLEENTITYSTATEEntry#OPEN}.
*/
public void setNewInstanceDefaults() {
setState(OPEN);
}
Note: If you find that new instances have a
number of possible initial states, then consider whether:
- calling code should be responsible for creating a new instance of your entity with a default state, and then immediately transitioning it to the required state; or
- you are trying to force logically different concepts to be stored on the same physical entity, and perhaps should instead consider using inheritance/polymorphism to separate out different behavior.