3 Replies Latest reply on Oct 5, 2010 2:32 PM by lvdberg

    Query to store information from the jbpm to a db

    vanz

      I have a TodoDoc.java document where I manage the process and from which I get 3 information to store in the db.
      I also have a Workflow.java document that is the entity I have to put the 3 information.


      I have a process definition. When I switch from one task to the next one I have to store in the database some information (like logged user, task description and name of the task). I have to put these information inside the entity (Workflow.java)


      The task description should be put in the idDocumento of the entity, the user and the name of the task inside the idStato.
      How can I create a query that would let me save these information inside the DB?


      todoDoc.java




      @Name("todoDoc")
      public class TodoDoc {
      
           private String description;
           private String nomeDoc = new String();
      
           EntityManager entityManager;
      
           @In
           Credentials credentials;
           
           public String getDescription() {
                return description;
           }
      
           public void setDescription(String description) {
                this.description = description;
           }
      
           @CreateProcess(definition = "todo")
           public void createTodo() {
                nomeDoc = description;
           }
      
           @CreateProcess(definition = "todo2")
           public void createTodo2() {
                nomeDoc = description;
           }
      
           @StartTask @EndTask
           public void conferma() {
                this.idprocesso();
                System.out.println("Nome Documento: "+TaskInstance.instance().getDescription());
                System.out.println("Stato Documento: "+TaskInstance.instance().getName());
                System.out.println("User: "+credentials.getUsername());
      //          String query="INSERT INTO Workflow (documento_fk,statoDocumento_fk) VALUES (?,?)";
      //          entityManager.createQuery(query).executeUpdate();     
      //          String query="INSERT INTO Workflow (documento_fk,statoDocumento_fk) VALUES("+TaskInstance.instance().getDescription()+","+TaskInstance.instance().getName()+")";
      //          entityManager.createQuery(query);
           }
      
           @StartTask
           @EndTask(transition = "rifiuta")
           public void rifiuta() {
                idprocesso();
           }
      
           public void idprocesso() {
                if ("redazione".equals(TaskInstance.instance().getName())) {
                     ProcessInstance.instance().getContextInstance().createVariable(
                               "Var", TaskInstance.instance().getDescription().toString());
                }
                nomeDoc = ProcessInstance.instance().getContextInstance().getVariable(
                          "Var").toString();
           }
      
           public String getNomeDoc() {
                return nomeDoc;
           }
      
           public void setNomeDoc(String nomeDoc) {
                this.nomeDoc = nomeDoc;
           }
      
           public EntityManager getEntityManager() {
                return entityManager;
           }
      
           public void setEntityManager(EntityManager entityManager) {
                this.entityManager = entityManager;
           }
      }



      Workflow.java



      @Entity
      public class Workflow implements Serializable
      {
          private Long id;
          private String name;
          private Documento documento;
          private StatoDocumento statoDocumento;
          private User user;
          
          @Id @GeneratedValue
          public Long getId() {
              return id;
          }
      
          public void setId(Long id) {
              this.id = id;
          }
      
          @Length(max = 20)
          public String getName() {
              return name;
          }
      
          public void setName(String name) {
              this.name = name;
          }
          
          @ManyToOne
          @JoinColumn(name="documento_fk")
           public Documento getDocumento() {
                return documento;
           }
      
           public void setDocumento(Documento documento) {
                this.documento = documento;
           }
      
           @ManyToOne
           @JoinColumn(name="statoDocumento_fk")
           public StatoDocumento getStatoDocumento() {
                return statoDocumento;
           }
      
           public void setStatoDocumento(StatoDocumento statoDocumento) {
                this.statoDocumento = statoDocumento;
           }
      
           @ManyToOne
           @JoinColumn(name="user_fk")
           public User getUser() {
                return user;
           }
      
           public void setUser(User user) {
                this.user = user;
           }
      
      }
      



        • 1. Re: Query to store information from the jbpm to a db
          lvdberg

          Hi,


          I am a bit confused when I read your objectives. Most things you want to do form part of the jBPM functionality and the integration with Seam makes this a relatively simple task. Storing entities in the businees context csn be done by outjecting it in the Business Context scope.


          Have you read the excellent free chapter of the Seam In Action book, where this is explained in detail ?


          Leo

          • 2. Re: Query to store information from the jbpm to a db
            vanz

            Sure, (particularly cap 14,Managing
            the business process
            ) but I don't understand how to save this information in my entity. Whenever I want to carry out an operation that is not related to the process management, an error comes up.


            In this specific case, I am able to display the information but not to save them permanently in the database.

            • 3. Re: Query to store information from the jbpm to a db
              lvdberg

              Hi,


              it depends where you want to store the data. Entities shouldn't be stored in the jBPM environment but in its own context. If it's just simple data and you don't want additional DB's use the BusinessContext scope and JBPM/Seam will do the rest.


              Leo