Can't save to DTO entity with DataManager

I have a simple DTO entity with a single integer field, count.

I need to contact a 3rd party API and save its return to that field:

RiskDetections riskDetections = dataManager.create(RiskDetections.class);
riskDetections.setCount(signinCount);
dataManager.save(riskDetections);

I have confirmed that signinCount is a none-null value.

However, when reading back the DTO entity, it is blank:

List<RiskDetections> signinCount = dataManager.load(RiskDetections.class).all().list();
        for (RiskDetections i : signinCount) {
            System.out.println(i.getCount());
        }

Can anyone spot what I’m missing here?

DTO entity stored only in memory during run of the application.
Such an object cannot be preserved in the database.
Entities :: Jmix Documentation

If you needsave entity in the database - use the JPA entity. Entities :: Jmix Documentation

You can find examples of working with DTO entities and external API in this project:

Thanks Konstantin.

In my case, I need to use DataManager to do the saving and loading, however I’m struggling to understand how to map the InMemoryStore to the DTO entity.

The InMemoryStore bean comes with some boilerplate code, such as getName, setName, etc. Do I need to modify these at all?

I think some added context is needed;

I have a Quartz job that periodically contacts the Microsoft Graph API and returns a value, this is the value I want to save in the DTO.

Having set up the InMemoryStore and its descriptor the best I can, I get an NPE.

Caused by: java.lang.NullPointerException: Cannot invoke "java.util.Collection.iterator()" because "c" is null

What do you mean by “saving in DTO”?
I can imagine a use case when your periodic job creates a DTO and saves to the in-memory data store, and then you read from it and show data in UI. Am I right?

That’s exactly what I’m looking to achieve.

OK, that should work.
You can see an example of a simple in-memory data store here:

See also the docs.

Let me know if something doesn’t work as expected.

Regards,
Konstantin

1 Like

Perfect, that’s working as intended now. Thank you for putting up with my stupidity.