Cannot install app component due to file descriptor class being used?

Hi,

I am getting the following error when trying to install a project as an app component to another project:

Exception Description: [class com.solutiondomain.fieldsolution.entity.Job] uses a non-entity [class com.haulmont.cuba.core.entity.FileDescriptor] as target entity in the relationship attribute [field attachedFiles].
11:47:16.552 ERROR c.h.c.c.s.AbstractWebAppContextLoader   - Error initializing application
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory_odk_local' defined in class path resource [com/solutiondomain/test2/spring.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.7.3.6-cuba): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [fieldsolution] failed.
Internal Exception: Exception [EclipseLink-7250] (Eclipse Persistence Services - 2.7.3.6-cuba): org.eclipse.persistence.exceptions.ValidationException

Is there anything I can do to allow the component to be installed since file descriptor is a built in class?

Thank you

Regards

Matt

Hi,
Do you use additional data stores in your project?
In which data store is the Job entity located?

Note that FileDescriptor always belongs to the main data store.

You can read here about cross-datastore references:
https://doc.cuba-platform.com/manual-7.1/data_store.html#cross_datastore_ref

Hi Alex,

We do use additional data stores in our project and Job is located in an additional datastore.

Ahh, I was not aware of that - so I’m guessing they just cannot be used in classes that are stored in additional datastores?

Thank you for your swift reply Alex

regards

Matt

They can be used, please read the docs :slight_smile:

Hi Alex,

I have read the documentation you linked but to no avail.

We are trying to achieve the following:

I keep getting errors like this:

Exception Description: [class com.solutiondomain.fieldsolution.entity.CalendarSetting] uses a non-entity [class com.haulmont.cuba.security.entity.User] as target entity in the relationship attribute [field user].

This is the Class attribute:

@ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CALENDAR_PREFERENCE_ID")
    protected CalendarPreference calendarPreference;

How should associated attributes be defined in the above scenario?

We also have some like this which also didn’t work:

            joinColumns = @JoinColumn(name = "JOB_ID"),
            inverseJoinColumns = @JoinColumn(name = "FILE_DESCRIPTOR_ID"))
    @ManyToMany(cascade = CascadeType.PERSIST)
    protected List<FileDescriptor> attachedFiles;

I changed to

@Transient
    @MetaProperty(related = "FILE_DESCRIPTOR_ID")
    protected List<FileDescriptor> attachedFiles;

But that still didn’t work (although the server did start)

I have made the changes as per this ticket:

Anything else required?

Thank you

Regards

Matt

Hi,

The error means that you are trying to reference User entity (that always lives in main data store) from entity CalendarSetting which lives in additional datastore, like they are in the same JPA schema, but they are not.

This link gives direct advise how to make things work: Data Stores - CUBA Platform. Developer’s Manual

The following code should be written in the CalendarSetting entity. Two attributes, one is persistent UUID and other is non-persistent link to entity:

@SystemLevel
@Column(name = "USER_ID")
private UUID userId;

@Transient
@MetaProperty(related = "userId")
private User user;

Also include non-persistent user attribute to appropriate views.

The documentation says that:

DataManager can automatically maintain TO-ONE references between entities from different data stores, if they are properly defined

You are trying to use many-to-many here, and it will not work. CUBA doesn’t support many-to-many cross-datastore references.
In this case you can refactor the data model. Instead of many-to-many association - create auxiliary entity “JobToFileDescriptor” that lives in additional data store and contains many-to-one link to Job and cross-datastore many-to-one link to FileDescriptor. Job will reference JobToFileDescriptor-s as a one-to-many relation.

Thank you for another quick response Alex, your assistance is greatly appreciated :slight_smile:

Regards

Matt