Can an entity be abstract?

The studio doesn’t have an option to make an entity abstract.

Can I just add abstract to any entity class?

Even if official JPA 1/2 specifications says that abstract @Entity classes are permitted, I’ve never seen them in practical use, and I’ll simply avoid them if you don’t have some specific requirement you have to fulfill.
Studio can’t create abstract entities, and I don’t know if it can open an entity class that is marked as abstract. But you can try for yourself by creating an entity in Studio, then change it to abstract, and re-open it in Studio.

You can safely mark a superclass as abstract, though. It can be used in JPA for classes marked with @MappedSuperclass, for example. See this article for a detailed explanation: Complete Guide: Inheritance strategies with JPA and Hibernate

You can create your abstract @MappedSuperclasses in your IDE, and you can use them as parents when creating new (concrete) entities in Studio.

1 Like

Hi @pfurini
Thank you for your reply.

I have used abstract entities in the past, in different use-cases.My question is not regarding jpa, but regarding the platform and why it there is no option in the studio. Did they just forgot about it, or are there certain issues or limitations in the platform?

In fact, in the client-order example described in Entity Inheritance - CUBA Platform. Developer’s Manual the client class is a typical example of an entity that could be abstract.

Perhaps I should rephrase my question to “Why is there no checkbox in studio to make a entity abstract and can I get into trouble if I make my class abstract manually?”

regards,
Tom

Hi Tom,

Yes you can make an entity abstract manually. I’ve just checked this on the example you mentioned, and I don’t see any issues at design and run time. Studio perfectly opens and edits such entity.

We are not going to add a checkbox to Studio UI because we think it’s quite minor thing and the UI is overloaded already.

Hi @konstantin

Thanks for the reply.

It’s not that i really want it in the UI that much. But if something is not is not expressed explicitly in the docs my alarms go off :smiley: , I’d rather ask than just trying it and running in problems later.