[jboss-user] [JBoss Portal] - Re: Cannot retrieve user: Unable to locate current JTA trans

sohil.shah@jboss.com do-not-reply at jboss.com
Mon Aug 6 16:58:34 EDT 2007


kpalania-

UserModule needs to be called within the context of an already active Transaction.

Try something like this:


  | SessionFactory identitySessionFactory = (SessionFactory)new InitialContext().lookup("java:/portal/IdentitySessionFactory");
  | Session session = identitySessionFactory.openSession();
  | Transaction transaction = session.beginTransaction();
  | boolean success = false;
  | try
  | {
  |         UserModule  userModule = (UserModule) new        InitialContext().lookup("java:portal/UserModule");
  | User user = userModule.findUserByUserName("admin");
  | 
  | //other business logic etc etc
  | 
  | success = true;
  | }
  | finally
  | {
  |          if (transaction != null)
  |          {
  |             if (success)
  |             {
  |                transaction.commit();
  |             }
  |             else
  |             {
  |                transaction.rollback();
  |             }
  |          }
  | 
  |          if (session != null)
  |          {
  |             session.close();
  |          }
  | }
  | 

This code maynot compile as is, but you get the idea ;)

Thanks

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4071367#4071367

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4071367



More information about the jboss-user mailing list