1 2 Previous Next 15 Replies Latest reply on Dec 26, 2005 5:48 AM by tom.baeyens

    Token reflects old node after a successful signal

    aron.gombas

      Hey,

      I have a very annoying problem with 3.0.2 that has very similar symptoms to these ones:
      http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3889539#3889539
      http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3889415

      What happens in my particular case is the following sequence:
      - tx begin
      - processIntance.signal()
      - saveProcessInstance(processInstance)
      - tx commit

      The TX is committed without exceptions and I can see the changed root-token node in the database, so the transition was performed successfully.
      This sounds fine, but if I load the process instance after these:

       session.getGraphSession().loadProcessInstance(processInstanceId);
      


      ...then its root token is still in the node that it was BEFORE the signal!

      The current workaround is that we close the old session and open new one when we detect this problem. (I guess it causes flushing all cached data in the background.)
      This is a web-app and normally, we have used the session-per-request pattern, so there is one session created for each request and that's retrieved with JbpmSession.getCurrentJbpmSession(); before each operation.
      I'm not sure if it's a problem with cache settings, Hibernate settings or a bug in JBPM?

        • 1. Re: Token reflects old node after a successful signal
          enazareno

          try commit and close.

          Regards,

          Elmo

          • 2. Re: Token reflects old node after a successful signal
            aron.gombas

             

            "enazareno" wrote:
            try commit and close.

            Thanks, Elmo, but that's exactly what I do.
            See my sentence above:
            The current workaround is that we close the old session and open new one

            This works as workaround, but I guess this is not the desired behaviour of jBPM.

            • 3. Re: Token reflects old node after a successful signal
              enazareno

              I was in a similar situation last week. But my case might be a litlle different from yours because I'm running mine in CMT. Anyway, I had noticed in your code you issued a commit only and did not use a commit and close the transaction as ff:

               JbpmSession s = JbpmSessionFactory.getInstance().openJbpmSession();
               try {
               s.beginTransaction();
               s.getGraphSession().saveProcessInstance( p );
               s.getSession().flush(); //might be optional
               s.commitTransactionAndClose(); //commit and close
               }
               catch( Exception e) {
               s.rollbackTransactionAndClose();
               }
              


              If you had done this already then disregard this suggestion. I am quite a newbie to hibernate and had to go to their site for more info. If its a persistence problem then its clearly about hibernate. A couple of info though that might be useful for you - when debugging in the server, set the hibernate.show_sql=true in jbpm.hibernate.properties so you can see the sql statements, at least I found that very useful. Use one JbpmSession per thread/request but the JbpmSessionFactory/configurations must be loaded only once. BTW, what database are you using?

              Elmo




              • 4. Re: Token reflects old node after a successful signal
                aron.gombas

                 

                "enazareno" wrote:
                Anyway, I had noticed in your code you issued a commit only and did not use a commit and close the transaction as ff:

                That's right.
                In my real code, I'm closing the session, too, but this is *only* a workaround. Should this whole thing work without closing the session? That seems weird to me.

                "enazareno" wrote:
                set the hibernate.show_sql=true in jbpm.hibernate.properties so you can see the sql statements, at least I found that very useful.

                I'm using it.

                "enazareno" wrote:
                Use one JbpmSession per thread/request but the JbpmSessionFactory/configurations must be loaded only once.

                Yep, I'm using the session-per-request pattern. It's a bit modified, as sometimes I need to reopen the session when this syncing problem is detected.

                "enazareno" wrote:
                BTW, what database are you using?

                We're running with MySQL 4.

                • 5. Re: Token reflects old node after a successful signal
                  ralfoeldi

                  Hi Aron,

                  it would be interesting to know in what transaction context you try to load the processInstance. You didn't mention that in your original post.

                  Greetings

                  Rainer

                  • 6. Re: Token reflects old node after a successful signal
                    aron.gombas

                    Rainer,

                    "RAlfoeldi" wrote:
                    it would be interesting to know in what transaction context you try to load the processInstance.

                    I'm not sure what you meant by "transaction context", but I actually start a new jBPM session, so the full seq is something like this:

                    - session open
                    ...
                    - tx begin
                    - processIntance.signal()
                    - saveProcessInstance(processInstance)
                    - tx commit
                    ...
                    - tx begin
                    - session.getGraphSession().loadProcessInstance(processInstanceId);
                    - tx commit
                    ...
                    - session close

                    Was this what you meant?

                    • 7. Re: Token reflects old node after a successful signal
                      enazareno

                      Hi Aron,

                      I'm using MySQL 4.1. Maybe you shouldn't re-use JbpmSession. Try opening a new session everytime and close it immediately, throw it away. Use JbmpSessionFactory.getInstance().openJbpmSession instead.

                      This is a web-app and normally, we have used the session-per-request pattern, so there is one session created for each request and that's retrieved with JbpmSession.getCurrentJbpmSession();


                      I think a JbpmSession represents one database connection. If you're worried about performance issues, don't be, IF you are using database connection pooling. Upon closing the jbpm session it does not actually close the connection but returns it to the pool. If you implement your own pooling, I suggest you instead let the container manage it, it is already provided and it takes away your headaches. If you're uncomfortable with hibernate like me, I don't let hibernate manage my pooling. But its quite easy to configure. In the hbm.hibernate.properties file you could add this entry:
                      hibernate.connection.datasource=[your datasource name]

                      and comment out connection settings in the jbpm.hibernate.cfg.xml.

                      Here was my problem. I am using JBoss. In a CMT (container managed transaction), it does not allow you to do a beginTransaction and commitTransaction. I only used saveProcessInstance. It inserts some data to the database but was incomplete. I was pretty sure that the problem was due to committing the data. I was able to solve this by doing the ff. statements (the flush and close statements was the key)

                       JbpmSession s = JbpmSessionFactory.getInstance().openJbpmSession();
                       try {
                       s.getGraphSession().saveProcessInstance( p );
                       }
                       catch( Exception e) {
                       //error handling here
                       }
                       finally {
                       try { s.getSession().flush(); } catch( Exception igmore ) {;}
                       try { s.close(); } catch (Exception ignore) {;}
                       }
                      


                      Anyway, this might not be the solution to your problem but it might give you an idea.

                      Regards,

                      Elmo

                      • 8. Re: Token reflects old node after a successful signal
                        aron.gombas

                         

                        "enazareno" wrote:
                        Try opening a new session everytime and close it immediately, throw it away. Use JbmpSessionFactory.getInstance().openJbpmSession instead.

                        Sure, that's what I'm doing, but again: this is *only* a workaround.
                        I get the current session with getCurrentJbpmSession(); When it returns NULL, I open a new one openJbpmSession(), as you've suggested.


                        • 9. Re: Token reflects old node after a successful signal
                          enazareno

                          Hi Aron,

                          What I'm suggesting is dont use getCurrentJbpmSession().

                          Regards,

                          Elmo

                          • 10. Re: Token reflects old node after a successful signal
                            enazareno

                            Hi Aron,

                            BTW, before I forget, please indicate the environment of your application ( the web server, version - are you using a J2ee container? are you using a datasource for your connections ? stuff like that).

                            I might be making the wrong assumptions - just in case

                            Regards,

                            Elmo

                            • 11. Re: Token reflects old node after a successful signal
                              aron.gombas

                               

                              "enazareno" wrote:
                              What I'm suggesting is dont use getCurrentJbpmSession().

                              Yep, Elmo, I understand, but I would definitely like to use the session-per-transaction pattern.

                              • 12. Re: Token reflects old node after a successful signal
                                aron.gombas

                                 

                                "enazareno" wrote:
                                please indicate the environment of your application ( the web server, version - are you using a J2ee container? are you using a datasource for your connections ?

                                We're running Tomcat 5.5.9, so it's not a managed environment.

                                Our datasource is provided by a JNDI entry in the context configuration:
                                <Resource name="jdbc/MyDatasource"
                                auth="Container" type="javax.sql.DataSource"
                                maxActive="20" maxIdle="10" maxWait="-1"
                                username="xxx" password="yyy"
                                driverClassName="com.mysql.jdbc.Driver"
                                url="jdbc:mysql://localhost:12751/zzz?autoReconnect=true"/>


                                ...and referenced from hibernate.cfg.xml as:
                                <property name="hibernate.connection.datasource">java:comp/env/jdbc/MyDatasource</property>



                                • 13. Re: Token reflects old node after a successful signal
                                  enazareno

                                  Hi Aron,


                                  Yep, Elmo, I understand, but I would definitely like to use the session-per-transaction pattern.


                                  I really can't suggest much at this point on what you are trying to achieve. Anyway, I'm looking at the 3.1 version right now and they have a much different implementation regarding the getting of resources (they have the JbpmSessionFactory deprecated). Maybe a solution there might fit your needs. Good luck and update this post if you have found something significant. It might help others. :)

                                  Regards,

                                  Elmo

                                  • 14. Re: Token reflects old node after a successful signal
                                    aron.gombas

                                     

                                    Anyway, I'm looking at the 3.1 version right now and they have a much different implementation regarding the getting of resources (they have the JbpmSessionFactory deprecated).

                                    That sounds interesting, I'll definitely take a serious look at this as soon as the first stable gets released.
                                    Thanks, Elmo, and merry X-mas to You! ;)


                                    1 2 Previous Next