public static void enforceNoLazyInitialization(ContentEntity content) {
   content.setCategory(
       content.getCategory() != null ? new CategoryEntity(content.getCategory()) : null);
   content.setAssignee(
       content.getAssignee() != null ? new UserEntity(content.getAssignee()) : null);
   content.setAssigner(
       content.getAssigner() != null ? new UserEntity(content.getAssigner()) : null);
   content.setOwner(content.getOwner() != null ? new UserEntity(content.getOwner()) : null);
   content.setLanguage(
       content.getLanguage() != null ? new LanguageEntity(content.getLanguage()) : null);
   content.setDraftVersion(
       content.getDraftVersion() != null
           ? new ContentVersionEntity(content.getDraftVersion())
           : null);
   content.setMainVersion(
       content.getMainVersion() != null
           ? new ContentVersionEntity(content.getMainVersion())
           : null);
 }
  @Test
  public void response_ok_for_request_to_content_image_that_binary_is_not_on_main_version()
      throws Exception {
    // setup: content
    byte[] bytes = loadImage("Arn.JPG");
    ContentKey contentKey =
        createImageContent(
            "MyImage.jpg", 2, bytes, "ImageCategory", new DateTime(2011, 6, 27, 10, 0, 0, 0), null);

    // setup: draft version of content
    ContentEntity content = fixture.findContentByKey(contentKey);
    ContentVersionEntity draftVersion = createDraftVersion("Arn.JPG");
    draftVersion.setContentDataXml(content.getMainVersion().getContentDataAsXmlString());
    content.setDraftVersion(draftVersion);
    content.addVersion(draftVersion);
    fixture.save(draftVersion);

    BinaryDataEntity binaryDataForDraftVersion = factory.createBinaryData("Arn.JPG", bytes.length);
    binaryDataForDraftVersion.setBlobKey(
        content.getMainVersion().getBinaryData("source").getBlobKey());
    fixture.save(binaryDataForDraftVersion);

    ContentBinaryDataEntity contentBinaryDataForDraftVersion =
        factory.createContentBinaryData("source", binaryDataForDraftVersion, draftVersion);
    draftVersion.addContentBinaryData(contentBinaryDataForDraftVersion);
    fixture.save(contentBinaryDataForDraftVersion);

    fixture.flushAndClearHibernateSesssion();

    // exercise & verify
    String imageRequestPath = "_image/" + contentKey + "/label/source.jpg";
    setPathInfoAndRequestURI(httpServletRequest, imageRequestPath);
    httpServletRequest.setParameter("_version", draftVersion.getKey().toString());
    httpServletRequest.setParameter("_background", "0xffffff");
    httpServletRequest.setParameter("_quality", "100");

    imageController.handleRequestInternal(httpServletRequest, httpServletResponse);

    assertEquals(HttpServletResponse.SC_OK, httpServletResponse.getStatus());
    assertTrue("Content Length", httpServletResponse.getContentLength() > 0);
    assertEquals("image/jpg", httpServletResponse.getContentType());
  }