cancel
Showing results for 
Search instead for 
Did you mean: 

Why? Variables of type ByteArray cannot be used to query

mgriffith
Champ in-the-making
Champ in-the-making
Hello all,

I have a POJO that I am using to create some meta-data for a user task, so that I may be able to link back to it from a MVC controller like Spring or Struts.  I was previously just doing this with a UUID, storing that in the task as a variable and using the task service to look up my task based on the UUID.  This was working fine, and when I went to extend this approach to use a POJO so that I could add additional information to the task that I might want later, I get an error on the query:
org.activiti.engine.ActivitiException: Variables of type ByteArray cannot be used to query
    org.activiti.engine.impl.QueryVariableValue.initialize(QueryVariableValue.java:46)

The code simply looks like this:

– In the TaskListener on create event:

String uuid = UUID.randomUUID().toString();
TaskMetaData taskMetaData= new TaskMetaData(uuid);
taskMetaData.setApprovalLinkURL("http://localhost:8080/activiti-rest/pages/approve.do?taskId=");
taskMetaData.setClaimLinkURL("http://localhost:8080/activiti-rest/pages/claim.do?taskId=");

String feedDescription= 
   "<h1>Workflow Task</h1><br/><div id=\"workflow_link\">"
   + "</div> | "
   + "<a href=\""
   + taskMetaData.getApprovalLinkURL()
   + taskMetaData.getId()
   + "\" title=\"Approve Task\">Approve Task</a> | "
   + "<a href=\""
   + taskMetaData.getClaimLinkURL()
   + taskMetaData.getId()
   + "\" title=\"Claim Task\">Claim Task</a> | <br/> ";

taskMetaData.setDescription(feedDescription);
  
// set the UUID as a process variable
task.setVariable("taskId", taskMetaData);

In my MVC model, I am trying to lookup the task via the task meta data object:


TaskMetaData taskMetaData= new TaskMetaData(taskId);
Task task = taskService.createTaskQuery().processVariableValueEquals("taskId", taskMetaData).singleResult();
if (task == null) {
   throw new ActivitiException("No such task");
}

It fails on the query due to the error stated above.  Below is my POJO:

public class TaskMetaData implements Serializable, Comparable<TaskMetaData> {

   private static final long serialVersionUID = 2932507457670328496L;
   private final String id;
   private String approvalLinkURL;
   private String claimLinkURL;
   private String description;
   
   public TaskMetaData(String id) {
      super();
      this.id = id;
   }
   
   public String getApprovalLinkURL() {
      return approvalLinkURL;
   }


   public void setApprovalLinkURL(String approvalLinkURL) {
      this.approvalLinkURL = approvalLinkURL;
   }


   public String getClaimLinkURL() {
      return claimLinkURL;
   }


   public void setClaimLinkURL(String claimLinkURL) {
      this.claimLinkURL = claimLinkURL;
   }


   public String getDescription() {
      return description;
   }


   public void setDescription(String description) {
      this.description = description;
   }


   public String getId() {
      return id;
   }

   @Override
   public boolean equals(Object obj) {
      if (obj == this) {
         return true;
      }
      if (obj == null || !getClass().equals(obj.getClass())) {
         return false;
      }
      TaskMetaData that = (TaskMetaData) obj;
      return this.id.equalsIgnoreCase(that.getId());
   }

   @Override
   public int hashCode() {
      return new HashCodeBuilder(11, 1117).append(id).toHashCode();
   }

   @Override
   public String toString() {
         
      return ToStringBuilder.reflectionToString(this,
            ToStringStyle.DEFAULT_STYLE);
   }

   @Override
   public int compareTo(TaskMetaData compare) {
      if (compare == null) {
         return 0;
      }
      String thatId = compare.getId();
      if (id != null && thatId != null) {
         return id.compareTo(thatId);
      } else {
         return 0;
      }

   }

}

Any/All replies are appreciated!

Thanks in advance,
MG
10 REPLIES 10

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
Because it simply is meant for things that do not need to be queried… It never will be either. The uuid approach you used was better

mgriffith
Champ in-the-making
Champ in-the-making
How can I add additional fields or meta data to the task?

I don't see why the Pojo is allowed to be set if it can't be queried.

– MG

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
You can put jpeg files in it, serialized pojo's etc.. All stuff that yo do not query, see it as a normal db blob. How often do you query IN blobs? You can add basic metadata in variables, like you do now. But maybe you want it in your domain model and have a cross reference.

Or enhance the bpmnparser to bemable to add your own extensions on te bpmn level. That is how it should be

mgriffith
Champ in-the-making
Champ in-the-making
By serialized pojo you mean a persistent domain model, such as a Jpa entity, is that correct?

frederikherema1
Star Contributor
Star Contributor
Not all DB's support using a BLOB as a condition in the where-clause (which kinda makes sense, potentially comparing loads of data).

A solution whould be to store the ID of your pojo as a seperate variable or create your own variable-type (search the forum on how to do this) which stores the ID and the ref to the byteArray in one variable-record.

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
By serialized pojo you mean a persistent domain model, such as a Jpa entity, is that correct?

No, just a serialized pojo. Activiti and how it 'stores' JPA entities is a different thing and only slightly related (the normal entitymanager is used to store the jpa entity and only a reference is stored in activiti)

mgriffith
Champ in-the-making
Champ in-the-making
Not all DB's support using a BLOB as a condition in the where-clause (which kinda makes sense, potentially comparing loads of data).

A solution whould be to store the ID of your pojo as a seperate variable or create your own variable-type (search the forum on how to do this) which stores the ID and the ref to the byteArray in one variable-record.

Did you see my TaskMetaData class above? It is a serialized pojo.  I guess I'm not sure what you mean, and such was the original reason for this post. If I understand you correctly, I should be able to store a serialized pojo and query it, which is what I am trying to do – which subsequently throws the exception.  Can you provide a code example?

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
You understood wrong, I is not possible to query bytearray variables, just like it is almost always senseless to query real blob data.

mgriffith
Champ in-the-making
Champ in-the-making
You understood wrong, I is not possible to query bytearray variables, just like it is almost always senseless to query real blob data.

I'm not disputing that I'm wrong. Clearly I am because I'm getting the exception. It's not clear to me how my pojo is considered a byte array variable…