Another question regarding auto increment key

The auto numbering was already discussed here but I have a further question.
My entity is derived from BaseIntegerIdEntity and I want the key to automatically increment. I am using SQL Server and didnt activate the auto increment function in the database. I am using both scenarios:
a) When the entity is created in the GUI, CUBA creates the incremented key value (no need to call e.g. the UniqueNumbersAPI). Everything OK.
b) When the entity is created “manually” in the business logic, the key stays NULL and and the insert command can not be executed. How to set the incremented key value? If the UniqueNumbersAPI should be used, which parameter should be passed to uniqueNumbers.getNextNumber()?

Always use Metadata.create(YourEntity.class) to create entities in your code. It will automatically assign identifiers when needed. The IDEA plugin even shows warnings when you invoke “new YourEntity()”.

Works perfectly. Thank you.