# how to load data from the database as local variables?

**URL:** <https://community.ofelia.com/t/how-to-load-data-from-the-database-as-local-variables/8620>\
**Category:** Q&A\
**Created:** [4 July 2017 10:32 UTC](https://community.ofelia.com/t/how-to-load-data-from-the-database-as-local-variables/8620 "2017-07-04T10:32:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![o.senouci](https://avatars.discourse-cdn.com/v4/letter/o/b38774/32.png) [@o.senouci](https://community.ofelia.com/u/o.senouci)\
**Post date:** [4 July 2017 10:32 UTC](https://community.ofelia.com/t/how-to-load-data-from-the-database-as-local-variables/8620/1 "2017-07-04T10:32:50Z")

</div>

Have a `service` task where I am trying to make financial calculations. The data comes from a bill and the bill contains a contract id (This is a persistence id). I was hoping to use that to load the contact and get its data.

I was planning to load the data inside a local variable by adding the code below to data \>\> local variable \>\> add \>\> Edit variable dialog \>\> edit expression dialog \>\> script  
However, I have no clue how to get the session. The session is required to call BusinessObjectDAOFactory.createDAO()

import org.bonitasoft.engine.bdm.BusinessObjectDAOFactory  
import org.bonitasoft.engine.session.APISession;

import com.company.model.Contract  
import com.company.model.ContractDAO

BusinessObjectDAOFactory daoFactory = new BusinessObjectDAOFactory();

ContractDAO contractDAO = daoFactory.createDAO(SESSION\_IS\_REQUIRECT, ContractDAO.class);  
Contract contract = contractDAO.findByPersistenceId(bill.contractId);

return contract;

---

<div class="post-metadata">

**Author:** ![xat](https://avatars.discourse-cdn.com/v4/letter/x/f07891/32.png) [@xat](https://community.ofelia.com/u/xat)\
**Post date:** [4 July 2017 11:06 UTC](https://community.ofelia.com/t/how-to-load-data-from-the-database-as-local-variables/8620/2 "2017-07-04T11:06:07Z")

</div>

As per version 7.4 I would use the following

import com.company.model.Contract  
import com.company.model.ContractDAO

def cont = contractDAO.findByPersistenceId(bill.contractId)

That does the trick. However Bonita discourages using non-business variables to store business data and you may not need declaring local variable in Bonita at all. Just get your bill in calculation script using DAO.

---

<div class="post-metadata">

**Author:** ![rabiei286\_1360710](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@rabiei286\_1360710](https://community.ofelia.com/u/rabiei286_1360710)\
**Post date:** [26 February 2018 06:05 UTC](https://community.ofelia.com/t/how-to-load-data-from-the-database-as-local-variables/8620/3 "2018-02-26T06:05:08Z")

</div>

Hi  
I need to know how should I have the DAO files to import them to my java project and work with them?

---

<div class="post-metadata">

**Author:** ![o.senouci](https://avatars.discourse-cdn.com/v4/letter/o/b38774/32.png) [@o.senouci](https://community.ofelia.com/u/o.senouci)\
**Post date:** [5 July 2017 07:48 UTC](https://community.ofelia.com/t/how-to-load-data-from-the-database-as-local-variables/8620/4 "2017-07-05T07:48:26Z")

</div>

It works. So thanks a lot. However I still don’t understand how `contractDAO` got initiated! It’s a bit strange that by importing the namespace, suddenly `contractDAO` cames to existence.

What happens if the BDM was named `com.company.model.contract`? Notice that the model name starts with a lowercase and not an upper case.

This will result in the DAO being named `com.company.model.contractDAO`.

In this case will the variable contractDAO exist or not since the class com.company.model.contractDAO has the same name?

Thanks a lot

---

<div class="post-metadata">

**Author:** ![abertiboni\_1364056](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@abertiboni\_1364056](https://community.ofelia.com/u/abertiboni_1364056)\
**Post date:** [3 April 2018 21:06 UTC](https://community.ofelia.com/t/how-to-load-data-from-the-database-as-local-variables/8620/5 "2018-04-03T21:06:35Z")

</div>

i have a problem with this

i am trying to do the same on a java class on an actor filter java class.

i create a table on my BDM called Userstest, with 2 fields.

username  
userpass

and it makes one query called **findByUsername**

my class is

/\*\*  
\*  
\*/  
package org.mycompany.connector;

import java.util.Arrays;  
import java.util.List;  
import java.util.logging.Logger;

import org.bonitasoft.engine.connector.ConnectorValidationException;  
import org.bonitasoft.engine.exception.BonitaException;  
import org.bonitasoft.engine.filter.UserFilterException;  
import org.bonitasoft.engine.api.LoginAPI  
import org.bonitasoft.engine.bdm.BusinessObjectDAOFactory  
import org.bonitasoft.engine.session.APISession;

import com.company.model.UserstestDAO;  
import com.company.model.Userstest;

public class UseridbynameImpl extends AbstractUseridbynameImpl {

```
@Override
public void validateInputParameters() throws ConnectorValidationException {
	//TODO validate input parameters here 	
	
}

@Override
public List<Long> filter(final String actorName) throws UserFilterException {
    try {
          final long processInstanceId = getExecutionContext().getProcessInstanceId();
          long processInitiator = getAPIAccessor().getProcessAPI().getProcessInstance(processInstanceId).getStartedBy();
          String UserInitiator=getAPIAccessor().getIdentityAPI().getUser(processInitiator).getUserName();
    	    	  Logger logger = Logger.getLogger("org.bonitasoft");
    	    	  logger.severe("Usuario Iniciador: " + UserInitiator);
    	      String reviewname="";
    	    
    	     ** List<Userstest> us = UserstestDAO.findByUsername("juan", 0, 100);
    	      **
    	      logger.severe("Cantidad: " + us.size());
    	      
    		  logger.severe("Usuario Revisor: " + reviewname);
    		  long IdManager = getAPIAccessor().getIdentityAPI().getUserByUserName(reviewname).getId();
    		  
    		  
    	      return Arrays.asList(IdManager);
    } catch (final BonitaException e) {
         throw new UserFilterException(e);
    }
}

@Override
public boolean shouldAutoAssignTaskIfSingleResult() {
	// If this method returns true, the step will be assigned to 
	//the user if there is only one result returned by the filter method
	return super.shouldAutoAssignTaskIfSingleResult();

}

```

}  
when i execute the program, i got the following error:

2018-04-03 18:01:22.174 -0300 GRAVE: org.bonitasoft Usuario Iniciador: walter.bates  
2018-04-03 18:01:22.176 -0300 GRAVE: org.bonitasoft.engine.execution.work.InSessionBonitaWork THREAD\_ID=495 | HOSTNAME=MacBook-Pro-de-Alejandro.local | TENANT\_ID=1 | The work [ExecuteFlowNodeWork: flowNodeInstanceId: 120068] failed. The failure will be handled.  
2018-04-03 18:01:22.179 -0300 GRAVE: org.bonitasoft.engine.execution.work.InSessionBonitaWork THREAD\_ID=495 | HOSTNAME=MacBook-Pro-de-Alejandro.local | TENANT\_ID=1 | org.bonitasoft.engine.core.process.instance.api.exceptions.SActivityStateExecutionException : “PROCESS\_DEFINITION\_ID=8569080591741980647 | PROCESS\_NAME=Pool | PROCESS\_VERSION=1.0 | PROCESS\_INSTANCE\_ID=10034 | ROOT\_PROCESS\_INSTANCE\_ID=10034 | FLOW\_NODE\_DEFINITION\_ID=6407571758219735293 | FLOW\_NODE\_INSTANCE\_ID=120068 | FLOW\_NODE\_NAME=review | org.bonitasoft.engine.core.filter.exception.SUserFilterExecutionException: groovy.lang.MissingMethodException: No signature of method: static com.company.model.UserstestDAO.findByUsername() is applicable for argument types: (java.lang.String, java.lang.Integer, java.lang.Integer) values: [alejandro, 0, 100]”  
org.bonitasoft.engine.core.process.instance.api.exceptions.SActivityStateExecutionException: PROCESS\_DEFINITION\_ID=8569080591741980647 | PROCESS\_NAME=Pool | PROCESS\_VERSION=1.0 | PROCESS\_INSTANCE\_ID=10034 | ROOT\_PROCESS\_INSTANCE\_ID=10034 | FLOW\_NODE\_DEFINITION\_ID=6407571758219735293 | FLOW\_NODE\_INSTANCE\_ID=120068 | FLOW\_NODE\_NAME=review | org.bonitasoft.engine.core.filter.exception.SUserFilterExecutionException: groovy.lang.MissingMethodException: No signature of method: static com.company.model.UserstestDAO.findByUsername() is applicable for argument types: (java.lang.String, java.lang.Integer, java.lang.Integer) values: [alejandro, 0, 100]  
at org.bonitasoft.engine.execution.StateBehaviors.mapActors(StateBehaviors.java:295)  
at org.bonitasoft.engine.execution.state.InitializingActivityWithBoundaryEventsStateImpl.beforeConnectors(InitializingActivityWithBoundaryEventsStateImpl.java:90)  
at org.bonitasoft.engine.execution.state.OnEnterOrOnFinishConnectorState.execute(OnEnterOrOnFinishConnectorState.java:59)  
at org.bonitasoft.engine.execution.state.OnEnterOrOnFinishConnectorState.execute(OnEnterOrOnFinishConnectorState.java:1)  
at org.bonitasoft.engine.execution.FlowNodeExecutorImpl.executeState(FlowNodeExecutorImpl.java:129)  
at org.bonitasoft.engine.execution.FlowNodeExecutorImpl.updateState(FlowNodeExecutorImpl.java:180)  
at org.bonitasoft.engine.execution.FlowNodeExecutorImpl.stepForward(FlowNodeExecutorImpl.java:164)  
at org.bonitasoft.engine.execution.FlowNodeExecutorImpl.executeFlowNode(FlowNodeExecutorImpl.java:338)  
at org.bonitasoft.engine.execution.work.ExecuteFlowNodeWork.work(ExecuteFlowNodeWork.java:85)  
at org.bonitasoft.engine.execution.work.TxBonitaWork$1.call(TxBonitaWork.java:48)  
at org.bonitasoft.engine.execution.work.TxBonitaWork$1.call(TxBonitaWork.java:1)  
at org.bonitasoft.engine.transaction.JTATransactionServiceImpl.executeInTransaction(JTATransactionServiceImpl.java:274)  
at org.bonitasoft.engine.execution.work.TxBonitaWork.work(TxBonitaWork.java:53)  
at org.bonitasoft.engine.execution.work.LockProcessInstanceWork.work(LockProcessInstanceWork.java:74)  
at org.bonitasoft.engine.execution.work.failurewrapping.TxInHandleFailureWrappingWork.work(TxInHandleFailureWrappingWork.java:42)  
at org.bonitasoft.engine.execution.work.failurewrapping.TxInHandleFailureWrappingWork.work(TxInHandleFailureWrappingWork.java:42)  
at org.bonitasoft.engine.execution.work.failurewrapping.TxInHandleFailureWrappingWork.work(TxInHandleFailureWrappingWork.java:42)  
at org.bonitasoft.engine.execution.work.InSessionBonitaWork.work(InSessionBonitaWork.java:58)  
at org.bonitasoft.engine.work.BonitaThreadPoolExecutor.lambda$submit$0(BonitaThreadPoolExecutor.java:90)  
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)  
at java.lang.Thread.run(Thread.java:745)  
Caused by: org.bonitasoft.engine.core.filter.exception.SUserFilterExecutionException: groovy.lang.MissingMethodException: No signature of method: static com.company.model.UserstestDAO.findByUsername() is applicable for argument types: (java.lang.String, java.lang.Integer, java.lang.Integer) values: [alejandro, 0, 100]  
at org.bonitasoft.engine.core.filter.impl.UserFilterServiceImpl.executeFilter(UserFilterServiceImpl.java:124)  
at org.bonitasoft.engine.userfilter.UserFilterServiceDecorator.executeFilter(UserFilterServiceDecorator.java:68)  
at org.bonitasoft.engine.execution.StateBehaviors.mapUsingUserFilters(StateBehaviors.java:315)  
at org.bonitasoft.engine.execution.StateBehaviors.mapActors(StateBehaviors.java:287)  
… 21 more  
Caused by: java.util.concurrent.ExecutionException: groovy.lang.MissingMethodException: No signature of method: static com.company.model.UserstestDAO.findByUsername() is applicable for argument types: (java.lang.String, java.lang.Integer, java.lang.Integer) values: [alejandro, 0, 100]  
at java.util.concurrent.FutureTask.report(FutureTask.java:122)  
at java.util.concurrent.FutureTask.get(FutureTask.java:192)  
at org.bonitasoft.engine.connector.impl.ConnectorExecutorImpl.getValue(ConnectorExecutorImpl.java:149)  
at org.bonitasoft.engine.connector.impl.ConnectorExecutorImpl.execute(ConnectorExecutorImpl.java:122)  
at org.bonitasoft.engine.core.filter.impl.UserFilterServiceImpl.executeFilterInClassloader(UserFilterServiceImpl.java:211)  
at org.bonitasoft.engine.core.filter.impl.UserFilterServiceImpl.executeFilter(UserFilterServiceImpl.java:116)  
… 24 more  
Caused by: groovy.lang.MissingMethodException: No signature of method: static com.company.model.UserstestDAO.findByUsername() is applicable for argument types: (java.lang.String, java.lang.Integer, java.lang.Integer) values: [alejandro, 0, 100]  
at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1498)  
at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1484)  
at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:53)  
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)  
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)  
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:141)  
at org.mycompany.connector.UseridbynameImpl.filter(UseridbynameImpl.groovy:39)  
at org.bonitasoft.engine.core.filter.impl.SConnectorUserFilterAdapter.execute(SConnectorUserFilterAdapter.java:66)  
at org.bonitasoft.engine.connector.impl.ConnectorExecutorImpl$ExecuteConnectorCallable.call(ConnectorExecutorImpl.java:206)  
at org.bonitasoft.engine.connector.impl.ConnectorExecutorImpl$ExecuteConnectorCallable.call(ConnectorExecutorImpl.java:176)  
at java.util.concurrent.FutureTask.run(FutureTask.java:266)  
… 3 more

Please i need help, i have been looking all day trying to make this work but the message is the same that the program doesn’t find that method.

any idea somebody why this doesn’t work???
