0 Replies Latest reply on Jul 31, 2014 9:24 AM by Soumya Bose

    jbpm 6.1.CR1 issue with DbUserGroupCallback while using integer id_user and id_role instead of varchar.

    Soumya Bose Newbie

      We have an issue with DbUserGroupCallback when we are using integer id_user and id_role instead of varchar.

      We have made following changes -

       

      Changed the jboss server's users.properties as -

       

      1=krisv

      2=john

       

      and roles.properties as -

       

      1=admin,analyst

      2=analyst,Accounting,PM

       

      We have jndi datasource configured as per documentation in AS's standalone.xml to point to mysql database ('jbpm'). And also have run the migration scripts within 'jbpm-installer/db/mysql5' and created tables for 'user', 'role' and 'user_has_role' where 'user_has_role' table having int id_user and id_role association.

       

      We have added a property file 'jbpm.usergroup.callback.properties' having following content -

       

      db.ds.jndi.name=java:jboss/datasources/jbpmDS

      db.user.query=select * from user where username = ?

      db.user.roles.query=select id_role from user_has_role where id_user = ?

      db.roles.query=select * from role where name = ?

       

      We have writtent a custom DbUserGroupCallBack to override the code where we are reading String id_user and setting String id_role into the role list within 'getGroupsForUser' method. I am calling that internally from my CustomDbCallbackProducer and pointed that in jbpm-console/WEB-INF/beans.xml as -

       

      <alternatives>

          <class>com.sample.custom.authentication.CustomUserGroupInfoProducer</class>

      </alternatives>

       

      Now when I restart the server, deployment is proper. But having issue when I am creating a new task and viewing the task list with logged in user '1'.

       

      Following exception I am getting while creating a new task -

       

      14:56:10,767 WARN  [org.drools.persistence.SingleSessionCommandService] (http-localhost-127.0.0.1-8080-2) Could not commit session: org.jbpm.workflow.instance.WorkflowRuntimeException: [evaluation:25 - Self Evaluation:2] -- org.hibernate.exception.ConstraintViolationException: Duplicate entry '1' for key 'PRIMARY'

          at org.jbpm.workflow.instance.node.WorkItemNodeInstance.internalTrigger(WorkItemNodeInstance.java:140) [jbpm-flow-6.1.0.CR1.jar:6.1.0.CR1]

          at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:162) [jbpm-flow-6.1.0.CR1.jar:6.1.0.CR1]

          at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerNodeInstance(NodeInstanceImpl.java:344) [jbpm-flow-6.1.0.CR1.jar:6.1.0.CR1]

          at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerCompleted(NodeInstanceImpl.java:303) [jbpm-flow-6.1.0.CR1.jar:6.1.0.CR1]

          at org.jbpm.workflow.instance.node.StartNodeInstance.triggerCompleted(StartNodeInstance.java:66) [jbpm-flow-6.1.0.CR1.jar:6.1.0.CR1]

          at org.jbpm.workflow.instance.node.StartNodeInstance.internalTrigger(StartNodeInstance.java:43) [jbpm-flow-6.1.0.CR1.jar:6.1.0.CR1]

          at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:162) [jbpm-flow-6.1.0.CR1.jar:6.1.0.CR1]

          at org.jbpm.ruleflow.instance.RuleFlowProcessInstance.internalStart(RuleFlowProcessInstance.java:35) [jbpm-flow-6.1.0.CR1.jar:6.1.0.CR1]

       

       

      Following exception I am getting while I am viewing task list -

       

      ==> server.log <==

      13:52:59,207 INFO  [stdout] (http-localhost-127.0.0.1-8080-3) ============== query to be executed :: select * from user_has_role where id_user = ?

      13:52:59,225 INFO  [stdout] (http-localhost-127.0.0.1-8080-3) userId :: 1

      13:52:59,234 INFO  [stdout] (http-localhost-127.0.0.1-8080-3) prepared statement :: org.jboss.jca.adapters.jdbc.jdk6.WrappedPreparedStatementJDK6@23223163

      13:52:59,257 INFO  [stdout] (http-localhost-127.0.0.1-8080-3) resultset size :: 0

      13:52:59,273 INFO  [stdout] (http-localhost-127.0.0.1-8080-3) ===========================================  within getGroupsForUser() ========================= roles :: [1, 2]

      13:52:59,295 WARN  [org.jbpm.services.task.persistence.TaskTransactionInterceptor] (http-localhost-127.0.0.1-8080-3) Could not commit session: java.lang.RuntimeException: Organizational entity already exists with [GroupImpl:'1'] id, please check that there is no group and user with same id

          at org.jbpm.services.task.persistence.JPATaskPersistenceContext.persistOrgEntity(JPATaskPersistenceContext.java:190) [jbpm-human-task-jpa-6.1.0.CR1.jar:6.1.0.CR1]

       

      After further drill down I can see, I can create and listing tasks using user '2'.

       

      Following are the user_has_role records in mysql db -

       

      mysql> select * from user_has_role where id_user = 2;

      +--+-------+-------+

      | id | id_user | id_role |

      +--+-------+-------+

      |  3 |       2 |       2 |

      +--+-------+-------+

      1 row in set (0.01 sec)

       

      mysql> select * from user_has_role where id_user = 1;

      +--+-------+-------+

      | id | id_user | id_role |

      +--+-------+-------+

      |  1 |       1 |       2 |

      |  2 |       1 |       3 |

      +--+-------+-------+

      2 rows in set (0.00 sec)

       

      following is my role table -

       

      mysql> select * from role;

      +----+----------------+

      | id | name           |

      +----+----------------+

      |  1 | Administrators |

      |  2 | analyst        |

      |  3 | admin          |

      +----+----------------+

      3 rows in set (0.00 sec)

       

       

      following is my user table -

       

      mysql> select * from user;

      +----+----------+----------+

      | id | username | password |

      +----+----------+----------+

      |  1 | 1        | krisv    |

      |  2 | 2        | john     |

      +----+----------+----------+

      2 rows in set (0.00 sec)

       

       

      I am attaching the details stack traces if that helps.

       

      Please advise how we can use user_id and role_id as integer instead of varchar? What all I am missing to acheave that in my approach?