5 Replies Latest reply on Feb 25, 2008 10:04 AM by ziphyre

    Can't get EL resolved

    ziphyre

      Hi,


      Hate to occupy that much the forum, but I couldn't find any solution.


      The #{identity.username} don't get resolved in a entityManager.createQuery(...), although It gets resolved in a log.info(....) method, here is the code and the result:



      @Stateless
      @Name("authenticator")
      public class AuthenticatorAction implements Authenticator
      {
          @Logger Log log;    
          @In Identity identity;    
          @PersistenceContext EntityManager entityManager;   
          
          public boolean authenticate()
          {
              log.info("username: #0", identity.getUsername());
              log.info("username: #{identity.username}");
              log.info("password: #0", identity.getPassword());
              log.info("password: #{identity.password}");
              try {
                   User u = (User) entityManager.createQuery("select u from User u 
                                 where u.phoneNumber=#{identity.username} and
                                 u.password=#{identity.password}").getSingleResult();
              }
              catch (Exception e) {
                   log.info("Authentication failed");
                   return false;
              }
              return true;
          }
      }



      the result:



      00:53:09,818 INFO  [AuthenticatorAction] username: test
      00:53:09,818 INFO  [AuthenticatorAction] username: test
      00:53:09,818 INFO  [AuthenticatorAction] password: testpass
      00:53:09,819 INFO  [AuthenticatorAction] password: testpass
      00:53:09,821 INFO  [STDOUT] Hibernate: 
          select
              user0_.id as id28_,
              user0_.password as password28_,
              user0_.fullName as fullName28_,
              user0_.phoneNumber as phoneNum4_28_ 
          from
              User user0_ 
          where
              user0_.phoneNumber=? 
              and user0_.password=?
      00:53:09,835 INFO  [AuthenticatorAction] Authentication failed




      As you can see, log.info("username: #{identity.username}"); gets resolved, but not in the query. What am I missing?

        • 1. Re: Can't get EL resolved
          nickarls

          Are you sure it doesn't get resolved? What is in the exception? Could be something else, example 1.2 in the manual looks pretty much like that...

          • 2. Re: Can't get EL resolved
            ziphyre

            Damn!


            I can't believe I've lost that much time on this. When I saw question marks on the log:


            where
                    user0_.phoneNumber=? 
                    and user0_.password=?



            I thought there was an error, and it never occurred to me to try with correct login info!! Thank you...


            Is there a paramater for turning off these '?' and to log actual parameters?

            • 3. Re: Can't get EL resolved
              nickarls

              Heh, once you go code blind your mind goes blank for other paths ;-)


              I can't recall seeing it in other forms than logging on org.hibernate.type and that might be a little verbose.


              Personally I wouldn't mind if there would be a hibernate.showboundparameters that would show the same output but with the real substituted values.


              Well, in any case thats a Hibernate issue, might even have a JIRA over there somwhere.


              BTW. You might want to catch a NoResultException in your case instead of the Exception...

              • 4. Re: Can't get EL resolved
                nickarls

                hibernate.show_bound_parameters that is...

                • 5. Re: Can't get EL resolved
                  ziphyre

                  Nicklas Karlsson wrote on Feb 25, 2008 09:07 AM:

                  BTW. You might want to catch a NoResultException in your case instead of the Exception...


                  Sure, thanks...