2 Replies Latest reply on Feb 27, 2004 11:48 AM by zapa

    "A CMR collection  may only be used within the  transaction

    zapa

      That's the message that JBoss / Tomcat gives me as I try to run a jsp that accesses 2 entity beans . I know it's not a "best practice" but after a lot of thought i decided this is best for what i'm curently trying to do .

      I initially thought the error was due to the fact that i'm using JSP's but after a few google searches i saw some guys writting session ejb's having the same problems .

      here is a bit of code :

      ...
      Object ref = jndiContext.lookup("HolderObjectLocalHome");
       HolderObjectLocalHome hohome = (HolderObjectLocalHome)PortableRemoteObject.narrow(ref , HolderObjectLocalHome.class);
       Collection hoz = hohome.findAll(); // code works here
      
       Iterator i = hoz .iterator(); // code works here
      
       while ( i.hasNext() ) {
       HolderObjectLocal hol = (HolderObjectLocal)i.next();
      
       Collection objz = hol.getObjects(); // code works here
       Iterator ii = objz.iterator(); // code stops working here
      ...
      

      I find it wierd how it only complains when i try to access the second collection .

      Any ideeas ?

      thanks

        • 1. Re:
          schrouf

          I am not sure, but the problem might be that there is more than one transaction triggered by your successive entity access. The retrived data is only valid during the transaction it was initialy fetched in. If (e.g. by a call to another method) a new transaction is started afterwards, the application server marks your 'old' data as out-of date and throws as exception.

          What are your transaction settings for your entity beans ? Required, RequiresNew, ... ? Maybe declaring some of your methods as "read-only" might help...

          My first step for clarifying your problem cause would be to wrap the your failing entity access into one single user transaction (your entity beans should use "Required" transaction attribute). This should ensure that all of your entity data access runs within the same single transaction !

          • 2. Re:
            zapa

            I have wrapped the code in a user transaction , following also another thread from here and it seems to be working , thanks