0 Replies Latest reply on Feb 29, 2008 8:48 AM by je le

    session/transction mandatory when calling UserModule/RoleMod

    je le Newbie

      I only need read only operations like getting list of role, user, etc...
      I notice that in order for a "MBeanProxy" to works, the call must be done inside a session (ok) but into a transaction too (?)

      here a working code :

      Session session = null;
      Transaction t = null;
       try {
       SessionFactory identitySessionFactory = (SessionFactory) new InitialContext().lookup("java:/portal/IdentitySessionFactory");
       session = identitySessionFactory.openSession();
       t = session.beginTransaction();
      
       MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
       RoleModule roleModule = (RoleModule) MBeanProxy.get(RoleModule.class,
       new ObjectName("portal:service=Module,type=Role"), mbeanServer);
      
       Set s = roleModule.findRoles();
       Iterator it = s.iterator();
       while (it.hasNext()) {
       // just dump role for the test
       System.out.println("roles : " + it.next());
       }
       } catch (Exception ex) {
       ex.printStackTrace();
       } finally {
       if (t != null) {t.rollback(); }
       if (session != null) {session.close();}
       }
      


      It's strange to start a transaction and always call a roolback !?!
      Am I actually making the request right !???

      My code will not be call from a protlet, mostly servlet/dwr.
      anyway adding a trans-attribute to portlet.xml doesn't work for me.
      <transaction>
       <trans-attribute>Required</trans-attribute>
      </transaction>
      


      Thanks