예제 #1
0
  /* (non-Javadoc)
   * @see edu.ku.brc.specify.datamodel.DataModelObjBase#forceLoad()
   */
  @Override
  public void forceLoad() {
    try {
      getCollectionObjects().size();
      getCollectionObjectKids().size();
      getChildren().size();

    } catch (org.hibernate.LazyInitializationException ex) {
      // This is temporary for Release 6.3.00 - rods 05/22/11
      DataProviderSessionIFace tmpSession = null;
      try {
        tmpSession = DataProviderFactory.getInstance().createSession();
        tmpSession.attach(this);
        getCollectionObjects().size();
        getCollectionObjectKids().size();
        getChildren().size();

      } catch (Exception exx) {
        ex.printStackTrace();

      } finally {
        if (tmpSession != null) {
          tmpSession.close();
        }
      }
    }
  }
  @Test
  @TestForIssue(jiraKey = "HHH-11179")
  public void testNonExistentLazyInitOutsideTransaction() {
    Session s = openSession();
    s.beginTransaction();
    Child loadedChild = s.load(Child.class, -1L);
    s.getTransaction().commit();
    s.close();

    try {
      loadedChild.getParent();
      fail("lazy init did not fail on non-existent proxy");
    } catch (LazyInitializationException e) {
      assertNotNull(e.getMessage());
    }
  }