Unable to import class Persistence in a new bean

Hello,
I can not import the class “Transaction” and “Persistence” in a Bean. I have an error message at compilation.
After checking, the files are in the right places. I don’t understand !

Code :

package com.company.performancecenter.core;

import org.springframework.stereotype.Component;
import com.company.performancecenter.entity.Departement;
import com.haulmont.cuba.Persistence;
import com.haulmont.cuba.core.Transaction;
import javax.inject.Inject;
import java.util.UUID;

@Component(NomCompletDepartement.NAME)
public class NomCompletDepartement {
    public static final String NAME = "PerformanceCenter_NomCompletDepartement";

    @Inject
    private Persistence persistence;
    public void miseAJourNomCompletDepartement(UUID entityId, String nomComplet){
        try (Transaction tx = persistence.getTransaction()){
            Departement departement = persistence.getEntityManager().find(Departement.class, entityId);
            if (departement != null){
                departement.setNomComplet(nomComplet);
            }
            tx.commit();
        }
    }
}

log.txt(2.1 KB)

Hi!

As far as I can see, your bean located in a global module. And Persistence and Transaction classes are not available there. Move the bean to core model. See the difference:

/home/strai1/DEV_CUBA/PerformanceCenter/modules/global/src/com/company/performancecenter/core/NomCompletDepartement.java

and

/home/strai1/DEV_CUBA/PerformanceCenter/modules/core/src/com/company/performancecenter/core/NomCompletDepartement.java

Thank you very much Alexander !
The problem is solved !

However, I don’t understand why the Bean I created just with a right click on “Middleware -> Beans -> new -> Bean” ended up at this location.

It was a bug of Studio 8.1, fixed in 8.2.