title: reading object from a different entity group within a transaction
body: <p>What im trying to do:</p>
  
  <pre><code>public void updatePremiumFeatureData(Key userKey, OrderItemsDTO orderItemsDTO) throws Exception {
          PersistenceManager pm = PMF.get().getPersistenceManager();
          Transaction txn = pm.currentTransaction();
  
          try {
              txn.begin();
  
              UserDTO userData = pm.getObjectById(UserDTO.class, userKey);
              PremiumFeatureDataDTO premiumFeatureData = userData.getPremiumFeatureData();
  
              for (OrderItemDTO orderItemDTO : orderItemsDTO.getItems()) {
                  ProductDTO productDTO = pm.getObjectById(ProductDTO.class, orderItemDTO.getProductKey());
  
                  if (productDTO.getType() == ProductType.PREMIUM_TEMPLATES) {
                      int months = getMonthsToIncrement(orderItemDTO, productDTO);
  
                      premiumFeatureData.incrementPremiumTemplateExpiryDateBy(months);
                  }
                  ...
              }
  
              txn.commit();
  
              cacheService.removeUser(userKey);
          } catch (Exception e) {
              GAELogger.logError(LOG, e);
              throw e;
          } finally {
              if (txn.isActive()) {
                  txn.rollback();
              }
              pm.close();
          }
      }
  </code></pre>
  
  <p>and in production on save it says:</p>
  
  <pre><code>java.lang.IllegalArgumentException: cross-group transaction need to be explicitly specified, see TransactionOptions.Builder.withXG
  </code></pre>
  
  <p>for:</p>
  
  <pre><code>ProductDTO productDTO = pm.getObjectById(ProductDTO.class, orderItemDTO.getProductKey());
  </code></pre>
  
  <p>I know i cannot write multiple entity groups in a transaction (unless i turn on cross-group transaction, which i do not want to)</p>
  
  <p>i have also tried class ProductDAO:</p>
  
  <pre><code>public ProductDTO getProductByKey(Key productKey) throws Exception {
          ProductDTO productDTO = null;
  
          PersistenceManager pm = PMF.get().getPersistenceManager();
  
          try {
              productDTO = pm.getObjectById(ProductDTO.class, productKey);
              ...
          } catch (Exception e) {
              GAELogger.logError(LOG, e);
              throw e;
          } finally {
              pm.close();
          }
  
          return productDTO;
      }
  </code></pre>
  
  <p>and then:</p>
  
  <pre><code>ProductDTO productDTO = new ProductDAO().getProductByKey(key);
  </code></pre>
  
  <p>instead of:</p>
  
  <pre><code>ProductDTO productDTO = pm.getObjectById(ProductDTO.class, orderItemDTO.getProductKey());
  </code></pre>
  
  <p>Is there a work around just for the read bit? i.e. i want to read an entity group in a transaction with no intention to write to it. Is this possible?</p>
  
  <p>work around:</p>
  
  <p>i had to load productDTOs into a map and then use data in map in transaction. something like:</p>
  
  <pre><code>Map&lt;Key, ProductDTO&gt; map = new HashMap&lt;Key, ProductDTO&gt;();
  for (OrderItemDTO orderItemDTO : orderItemsDTO.getItems()) {
      ProductDTO productDTO = pm.getObjectById(ProductDTO.class, orderItemDTO.getProductKey());
      map.put(productDTO.getKey(), productDTO);
  }
  </code></pre>