How manage sys_file table?

Hi,
I have a question on the “sys_file” table…In my application on startup some file are loaded and stored in DB.
Now the size of the table “sys_file” is growing, and so I would on startup application delete all files in the table “sys_file” and also delete these files from file system.
I tried something like this:

Transaction tx = persistence.createTransaction();
        EntityManager em = persistence.getEntityManager();
        TypedQuery<FileDescriptor> query = em.createQuery(
                "select o from sys_file o", FileDescriptor.class);
        return query.getResultList();

to retrieve the files, but I get the following error:

15:32:32.171 ERROR c.h.cuba.core.sys.ServiceInterceptor    - Exception: 
java.lang.IllegalArgumentException: MetaClass not found for sys_file
	at com.haulmont.cuba.core.sys.CachingMetadataSession.getClassNN(CachingMetadataSession.java:67) ~[cuba-global-7.2.8.jar:7.2.8]
	at com.haulmont.cuba.core.sys.MetadataImpl.getClassNN(MetadataImpl.java:334) ~[cuba-global-7.2.8.jar:7.2.8]
	at com.haulmont.cuba.core.sys.PersistenceSecurityImpl.applyConstraints(PersistenceSecurityImpl.java:84) ~[cuba-core-7.2.8.jar:7.2.8]
	at com.haulmont.cuba.core.app.JpqlQueryBuilder.applyConstraints(JpqlQueryBuilder.java:273) ~[cuba-core-7.2.8.jar:7.2.8]
	at com.haulmont.cuba.core.app.JpqlQueryBuilder.getQuery(JpqlQueryBuilder.java:167) ~[cuba-core-7.2.8.jar:7.2.8]
	at com.haulmont.cuba.core.app.RdbmsStore.createQuery(RdbmsStore.java:767) ~[cuba-core-7.2.8.jar:7.2.8]
	at com.haulmont.cuba.core.app.RdbmsStore.loadList(RdbmsStore.java:240) ~[cuba-core-7.2.8.jar:7.2.8]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_251]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_251]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_251]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_251]
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.2.3.RELEASE.jar:5.2.3.RELEASE]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) [spring-aop-5.2.3.RELEASE.jar:5.2.3.RELEASE]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) [spring-aop-5.2.3.RELEASE.jar:5.2.3.RELEASE]
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95) [spring-aop-5.2.3.RELEASE.jar:5.2.3.RELEASE]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) [spring-aop-5.2.3.RELEASE.jar:5.2.3.RELEASE]
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) [spring-aop-5.2.3.RELEASE.jar:5.2.3.RELEASE]
	at com.sun.proxy.$Proxy286.loadList(Unknown Source) ~[na:na]
	at com.haulmont.cuba.core.app.DataManagerBean.loadList(DataManagerBean.java:78) ~[cuba-core-7.2.8.jar:7.2.8]

any suggest?
thanks in advance

This is the header for the FileDescriptor class:

@javax.persistence.Entity(name = "sys$FileDescriptor")
@Table(name = "SYS_FILE")
@NamePattern("%s (%s)|name,createDate,extension")
@SystemLevel
public class FileDescriptor extends StandardEntity implements TenantEntity

Please use entity name in JPQL, not table name. In your case, you should have something like this:

select o from sys$FileDescriptor o

But you can do it simpler using data manager instead of entity manager:

dataManager.load(FileDescriptor.class).list();

Thanks @belyaev the query works (I changed sys_file with sys$FileDescriptor), but now if I want retrieve and delete all these files from file system, how can I do it ?

Please use com.haulmont.cuba.core.app.FileStorageAPI#removeFile to remove the file itself and then remove FileDescriptor using DataManager or EntityManager.