3 Replies Latest reply on Nov 21, 2007 9:13 AM by Terry

    Why does EntityQuery auto save updates?

    Terry Apprentice

      Seems there is a link between EntityHome.instance() and EntityQuery or both refer to same instance of Entity?

      My changes get updated to database when I 'execute a query' to get current data in database.

      I have a jsf form based on EntityHome which updates few fields. Before committing changes to database I would like to compare values in database with values changed by the user. Therefore, I execute query -attached-. But I noticed, running query first committs my changes to database and then query it back.

      Is it possible to stop this behaviour? so what else can I do?

      Seam 1.2.1GA.

      Query that auto updates Client
      EntityQuery query = new EntityQuery();
      query.setEjbql("select client from Client client where lower(id)=lower('"+ id + "')");
      List<Client> client = query.getResultList();

        • 1. Re: Why does EntityQuery auto save updates?
          Terry Apprentice

          I guess it is related to how SEAM handles transactios. I'm using Seam POJOs.

          The EntityQuery's getResultSet() method is marked @transactional. Call to getResultSet() commits changes made to Client entity on the jsf form get committed to the database.

          Anyone knows why getResultSet() first committed changes to queried Entity. and how I can avoid it in my case?

          I guess it's a common issue, I can't find solution since this is my first attempt on such scenarion.

          • 2. Re: Why does EntityQuery auto save updates?
            Pete Muir Master

            The persistence context is automatically flushed at container invoked method boundaries unless you use flush mode manual.

            • 3. Re: Why does EntityQuery auto save updates?
              Terry Apprentice

              thanks Pete, yeah I figured that out.

              in my case I have a single jsf page. to get my code working, now I specified its scople to conversation; and save the current entity record in page action method, and then use it in update action method to compare if required data columns have been modified by the user.

              I am not sure if that is the right way, when wanting to compare user changes with record data in database? but it now works for me.