Hi Asad, just for curiosity.. why you would need to query tasks using variables? I don't know how you could make it, as task input and output seems to be serialized in Content table. You could query tasks by other criteria (from Task, TaskSummary, OrganizationalEntity) as it is done in orm.xml places in human tasks. You can just create an EntityManagerFactory like
entityManagerFactory = Persistence.createEntityManagerFactory("org.drools.task")
And then use the EntityManager to make queries.
About getting access to task variables, as said before, they are serialized content. You can check here to see how to get the variables:
http://dcalca.wordpress.com/2011/05/06/variables-in-jbpm5-human-tasks/
http://dcalca.files.wordpress.com/2011/05/input.png
Regards,
Demian