1 Reply Latest reply on Apr 18, 2008 4:23 PM by Hans Schlegel

    entityManager weirdness

    Simon Bailey Newbie


      how can i prevent entityManager from calling a flush when it goes out of context in a bean?

      for instance, in my AuthenticatorAction, i have the following code:

      public boolean authenticate() {
        try {
          User u = (User) em.createQuery(
            "from User where username = :username").setParameter(
            "username", identity.getUsername())
          if (!compareHash(u.getHashedPassword(), 
                identity.getPassword())) {
              .add("Wrong password for #{identity.username}");
              return false;
          loggedInUser = u;
          return true;
        } catch (NoResultException ex) {
            .add("#{identity.username} does not exist!");
          return false;

      this always calls an update on the User being queried. i was having the same problem occur in some validator beans that i have as well, which i prevented by adding

      .setHint("org.hibernate.readOnly", new Boolean(true))

      to the


      is there any other way to prevent this db round-trip?