2 Replies Latest reply on Jul 22, 2008 10:04 AM by bashan

    Create annotation persist object problem.

    bashan

      Hi,


      I have an activation page which activates user account when clicking on email link.
      I set the user as active using @Create annotation. It seems like the user object is not being persisted for some reason. In other places in my application objects are being persisted. Is it possible persisting the object on @Create method? Is there a better way of setting user as active from a direct mail link?


      Thanks,
      Guy.

        • 1. Re: Create annotation persist object problem.
          vdweij

          Guy,


          The create annotation is simply called after your component (containing the annotation) has been instantiated. It doesn't tell the EntityManager to persist some newly created object.


          If you post relevant part of your code it should provide more information to solve your problem. My best bet at this moment is that you have to explicitly persist the user account.

          • 2. Re: Create annotation persist object problem.
            bashan

            I do persist the object, maybe the transaction is not committed? In other screens, when I persist object inside an action it seems to be working fine.


            this is my bean:



            @Name("activation")
            public class ActivationAction
            {
              @In
              private User user;
            
              private FacesMessages facesMessages;
            
              @In
              Session myDatabase;
            
              @Logger
              private Log log;
            
              @In
              private UserDAO userDAO;
            
              @RequestParameter("confirmationCode")
              private String confirmationCode;
              
              private String status;
            
              @Create
              public void activateAccount()
              {
                User user = userDAO.getUserByActivationCode(confirmationCode);
                if (user != null)
                {
                  if (user.getStatus() == UserStatus.NEW)
                  {
                    log.info("Activating account for new user: #{user.email} (#{user.userId}), activation code: #{param['confirmationCode']}");
                    user = (User)myDatabase.merge(user);
                    user.setStatus(UserStatus.ACTIVE);        
                    myDatabase.persist(user);
                    status = "activated";
                  }
                  else
                  {
                    log.info("Account was already activated for user: #{user.email} (#{user.userId}), activation code: #{param['confirmationCode']}");
                    status = "alreadyActive";
                  }
                }
                else
                {
                  log.info("No user was found for activation code: #{param['confirmationCode']}");
                  status = "notFound";
                }
              }
            
              public String getStatus()
              {
                return status;
              }
            }