Upgrading to CUBA 6.8 : abstract superclass Entity, how to circumvent "Unable to instantiate entity" issue

Hi

We have moved from 6.7.9 to 6.8.3 and met the following issue.

With the following model:

  • abstract entity Counterpart with relation to Contact defined this way:
@DiscriminatorColumn(name = "DTYPE", discriminatorType = DiscriminatorType.STRING)
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "APP_COUNTERPART")
@Entity(name = "app$Counterpart")
@NamePattern("%s %s %s|title,name,internalCode")
@EnableRestore
public abstract class Counterpart extends StandardEntity {
    @Composition
    @OnDelete(DeletePolicy.CASCADE)
    @OneToMany(mappedBy = "counterpart")
    protected List<Contact> contacts = new ArrayList<>();
  • concrete Customer extends Counterpart
  • concrete Provider extends Counterpart
  • concrete Contact class with counterpart attribute defined this way:
@ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "COUNTERPART_ID")
   protected Counterpart counterpart;`

The following code is working on 6.7.9:

        View cpartView = new View(Counterpart.class);
        cpartView.addProperty("name");
        cpartView.addProperty("internalCode");

        View conView = new View(Contact.class);
        conView.addProperty("name");
        conView.addProperty("counterpart", cpartView);

        View cusView = new View(Customer.class);
        cusView.addProperty("internalCode");
        cusView.addProperty("contacts", conView);

        LoadContext<Customer> lc = LoadContext.create(Customer.class).setView(cusView);
        lc.setQueryString("select e from app$Customer e where e.internalCode = 'client'");
        dataManager.loadList(lc);

But will raise an exception in 6.8.3 (not tested for other 6.8.x)

java.lang.RuntimeException: Unable to instantiate entity

	at com.haulmont.cuba.core.app.AttributeSecuritySupport.isAttributeAccessEnabled(AttributeSecuritySupport.java:274)
	at com.haulmont.cuba.core.app.RdbmsStore.lambda$needToApplyAttributeAccess$4(RdbmsStore.java:897)
	at com.haulmont.cuba.core.app.RdbmsStore.needToApplyByPredicate(RdbmsStore.java:908)
	at com.haulmont.cuba.core.app.RdbmsStore.needToApplyAttributeAccess(RdbmsStore.java:897)
	at com.haulmont.cuba.core.app.RdbmsStore.createRestrictedView(RdbmsStore.java:599)
	at com.haulmont.cuba.core.app.RdbmsStore.loadList(RdbmsStore.java:206)
	at com.haulmont.cuba.core.app.DataManagerBean.loadList(DataManagerBean.java:84)
[...]
Caused by: java.lang.InstantiationException
	at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at java.lang.Class.newInstance(Class.java:442)
	at com.haulmont.cuba.core.app.AttributeSecuritySupport.isAttributeAccessEnabled(AttributeSecuritySupport.java:272)
	... 38 more

Through debugging root cause appears to be AttributeSecuritySupport.isAttributeAccessEnabled() trying to instantiate the abstract entity Counterpart.

It’s good news that this code will, as I understand it, be deprecated in the future. In the meantinme, in order to bypass it cuba.useSpringApplicationEventsToSetupAttributeAccess in app-core should be set to false.

As far as my research did go, this property is not documented, and would deserve it.

Mike

Thanks for reporting the problem. We’ll add this to the release notes, perhaps as a known issue.