Define customized superclass


Can i create a custom superclass for all entities?


public class Customer extends StandardEntity

Define superclass

public class MyStandarEntity extends StandardEntity


public class Customer extends MyStandarEntity 

I have the following error:
java.lang.IllegalStateException: Entity has no attribute applicable for table id column

Hi Francesco,

Sure, you can define your own superclass. You should annotate it as


or just select MappedSuperclass checkbox in Enity editor in CUBA Studio.

According to the documentation, it ‘defines that the class is an ancestor for some entities and its attributes must be used as part of descendant entities. Such class is not associated with any particular database table’.

See an example in the attachment.

Aleksey (25.6K)

I forgot to edit persistence.xml. Now works.

Another question.
I would like set Field1 ( the field is not in DB ) during instantiation of MyStandardEntity object.
In my applications Spring based , I do this in the rowMapper .
How should I do it in Cuba?

thanks again


If you don’t want a property to be stored in the DB, add @Transient annotation to it:

    protected String field1;

Regarding property initialization ‘during instantiation’, I’m not quite sure what you mean here.

  1. If the question is about new instance creation you can simply add initialization logic to the constructor:

public class MyStandardEntity extends StandardEntity {
    private static final long serialVersionUID = 7505674951206475460L;

    protected String field1;
    public MyStandardEntity() {
        this.field1 = UUID.randomUUID().toString();;
  1. If you mean initialization on reading entity from DB, just create before detach entity listener:

public class MyStandardEntityListener implements BeforeDetachEntityListener<MyStandardEntity> {
    public void onBeforeDetach(MyStandardEntity entity, EntityManager entityManager) {

Documentation on entity listeners can be found here.

Also, it would be helpful to have a look at the ‘Assigning Initial Values’ section of the documentation.