UUID or Entity as parameter for Service

I am trying to populate some default data in database based on the user action but having some error where I understand I might have been messing up the parameter rules of Entity and UUID! Thanks for your help guiding me. The details are as follows:

Method in controller:

public void onClickInsertStages(Component source) {
        planningService.loadProductionStagesToBOM((BillOfMaterial) billOfMaterialDs.getItem());

method in Service:

    public void loadProductionStagesToBOM(BillOfMaterial billOfMaterialId){
        try (Transaction tx = persistence.createTransaction()) {
            TypedQuery<BillOfMaterialCapacityRequirements> query1 = persistence.getEntityManager().createQuery(
                    "select e from demo$BillOfMaterialCapacityRequirements e where e.billOfMaterial.id = ?1",
                    BillOfMaterialCapacityRequirements.class).setParameter(1, billOfMaterialId.getId());
            List<BillOfMaterialCapacityRequirements> requirementsListList = query1.getResultList();

                TypedQuery<FactoryProductionStage> query2 = persistence.getEntityManager().createQuery(
                        "select e from demo$FactoryProductionStage e", FactoryProductionStage.class);
                List<FactoryProductionStage> stageList = query2.getResultList();

                if(stageList.size()>0) {
                    for (FactoryProductionStage stage : stageList) {
                        BillOfMaterialCapacityRequirements requirements = metadata.create(BillOfMaterialCapacityRequirements.class);






com.haulmont.cuba.core.sys.javacl.compiler.CharSequenceCompilerException: Compilation failed. Causes: 
BillOfMaterialEdit.java:95: error: incompatible types: com.company.entity.BillOfMaterial cannot be converted to java.util.UUID
        planningService.loadProductionStagesToBOM((BillOfMaterial) billOfMaterialDs.getItem());
                                                  ^ Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output 
	at com.haulmont.cuba.core.sys.javacl.compiler.CharSequenceCompiler.compile(CharSequenceCompiler.java:178)
	at com.haulmont.cuba.core.sys.javacl.JavaClassLoader.loadClass(JavaClassLoader.java:167)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
	at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:677)
	at com.haulmont.cuba.core.sys.AbstractScripting$CubaGroovyClassLoader.loadClass(AbstractScripting.java:450)
	at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:545)
	at com.haulmont.cuba.core.sys.AbstractScripting.loadClass(AbstractScripting.java:267)
	at com.haulmont.cuba.gui.WindowManager.preloadMainScreenClass(WindowManager.java:416)
	at com.haulmont.cuba.gui.WindowManager.createWindow(WindowManager.java:363)
	at com.haulmont.

Your code looks correct. Perhaps you didn’t change the signature of your service method in the planningService interface.

And use either declarative transactions with @Transactional or programmatic. Not both. However it doesn’t relate to the error.

This is the interface

public interface PlanningService {
    String NAME = "demo_PlanningService";

    void loadProductionStagesToBOM(BillOfMaterial billOfMaterial);

Try to execute Clean and then Assemble.

I have done that just after sending you my previous response, also removed programmatic transaction before doing clean and assemble. Now the error is gone. But, the billOfMaterial field is empty in the database in Entity BillOfMaterialCapacityRequirements.

As you see i have used this code to load it but did’t work…


I have debugged it and saw the value is there at runtime … not sure why only this field is not saved…

You can check what SQL is executed on database:

  • Open Administration > Server Log > Options
  • Select “eclipselink.sql” in Logger, “DEBUG” in Level, and press Set
  • Go to View tab and press Show Tail and select Refresh checkbox.
    Then see the log after executing your method. There should be INSERT statements with values.