Doubt about persistent and non-persistent entities

Good afternoon,

I wanted to ask a question that may sound silly but I just started with the platform and I have many doubts. I’m seeing that you can create persistent and non-persistent entities, up to there all right. The first thing is to know how I create these non-persistent entities, and the second, if I think they are not persistent, can I generate windows in the same way? Or am I forced to create them persistent?

Thank you very much,
Greetings.

Hi,

First of all, let me cite documentation about the difference between these two kinds of entities:

Persistent – instances of such entities are stored in the database using ORM.
Non-persistent – instances exist only in memory, or are stored somewhere via different mechanisms.

So the persistent entity is a natural choice if you want to represent data stored in a relational database table. On the other hand, if you need to represent data loaded, for example, from a web service, you need a non-persistent entity.

Now about your questions.

how I create these non-persistent entities

The same way as persistent ones - go to Data model section in Studio, click New > Entity and select Not persistent in Entity type field. Of course, you can do it right in the source code without Studio, but then you need some experience, and I would suggest first watching the changes made by Studio while you are using its visual interface.

if they are not persistent, can I generate windows in the same way?

For the UI framework, there is no difference between persistent and non-persistent entities, i.e. all UI components work with both ones in the same way. The difference is only in loading/saving the entities. For persistent entities, you can just specify a JPQL query in a collection datasource, and it will load the entities. For non-persistent entities, you need to do it programmatically by the obvious reason - the framework doesn’t know where to find your data. One of the ways of loading non-persistent entities is using CustomCollectionDatasource like in this example.

You can generate a standard browser/editor screens for a non-persistent entity in Studio, but they won’t show any data - you need to handle it in the code.

Hello,

Thank you very much for the reply. Then we can confirm that using non-persistent entities I can not have problems with the search components that are in the windows right? Even the personalized searches?

If so, do you have an example at hand of how to do all this?

Thank you very much again,
Greetings.

When I told you in the previous comment that “all UI components work with both ones in the same way” I should have made one exception - the generic Filter component. Actually, it affects loading of entities by modifying the JPQL query, hence it is useless for non-persistent entities.

So currently, when you work with non-persistent entities, you have to create your own filter using standard components like TextField, DateField, etc. and use values of these components when loading your entities.

In the future, we are going to decouple the generic Filter component from JPQL queries to enable its usage with custom data stores working with databases or web services not necessarily via JPA and JPQL. Then implementors of such data stores will be able to define also the logic of mapping filter condition to the query language of their data store.

Good Morning,

Thank you very much for your answer, you have clarified several doubts I had. If a new one comes up, I’ll steal some of your time :slight_smile:

Greetings.

Good Morning,

Another question, if I want to list results obtained through a REST service, is it also affected? All this when ordering and paging these results.

Thank you very much,
Greetings.

Hi,

Sorting by clicking on table columns will work. Paging is performed by setting firstResult/maxResults properties of your datasource, so you can use these properties when loading data from your web service.