2 Replies Latest reply on Aug 29, 2008 12:35 AM by bashan

    Webremote and database persist

    bashan

      Hi,


      I am having a little problem persisting one of my objects in a webremote method.
      This is my method:


        @WebRemote
        public void countView(Integer videoId)
        {
          Video video = videoDAO.getVideo(videoId);
          video.setViews(video.getViews() + 1);
          myDB.persist(video);
        }
      



      The code is called and no exception is raised, but object is not persisted to database.
      Without using webremote I have no problem persisting the object.
      Does anyone know what is going on? Maybe the transaction is not automatically comitted when using webremote?


      Thanks,
      Guy.

        • 1. Re: Webremote and database persist
          bashan

          Does anyone has any clue about this problem?

          • 2. Re: Webremote and database persist
            bashan

            Actually, I found a working solution, but I am not sure I understand why the original code is not working. This is the solution:


              @WebRemote
              public void countView(Integer videoId) throws Exception
              {
                Transaction.instance().begin();
                Video video = videoDAO.getVideo(videoId);
                video.setViews(video.getViews() + 1);
                nikoniansDatabase.persist(video);
                Transaction.instance().commit();
              }